Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voucher: Finished module that generates voucher without stripe webhook #109

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"cSpell.words": ["Qare"],
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"python.analysis.autoImportCompletions": true
"python.analysis.autoImportCompletions": true,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"pg": "^8.10.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"slugify": "^1.6.6",
"stripe": "^11.16.0",
"typeorm": "^0.3.12",
"typeorm-naming-strategies": "^4.1.0",
Expand Down
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import { OperationModule } from './modules/operation-saving/operation.module';
import { WaitingModule } from './modules/waiting-list/waiting.module';
import { ContactModule } from './modules/contact/contact.module';
import { BlogModule } from './modules/blog/blog.module';

Check warning on line 29 in src/app.module.ts

View check run for this annotation

Codecov / codecov/patch

src/app.module.ts#L29

Added line #L29 was not covered by tests

@Module({
imports: [
Expand Down Expand Up @@ -60,6 +61,7 @@
MessagingModule,
SMSModule,
ObjectStorageModule,
BlogModule
],
controllers: [],
providers: [
Expand Down
41 changes: 41 additions & 0 deletions src/modules/blog/blog.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {

Check warning on line 1 in src/modules/blog/blog.controller.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.controller.ts#L1

Added line #L1 was not covered by tests
Body,
Controller,
Get,
Param,
Post
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';

Check warning on line 8 in src/modules/blog/blog.controller.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.controller.ts#L8

Added line #L8 was not covered by tests
import { _403, _404, _409 } from '../../common/constants/errors';
import { Public } from 'src/common/decorators/public.decorator';
import { CreateBlogDto } from './dto/blog.dto';
import { BlogService } from './blog.service';

Check warning on line 12 in src/modules/blog/blog.controller.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.controller.ts#L10-L12

Added lines #L10 - L12 were not covered by tests
import slugify from 'slugify';

@ApiTags('Blogs')
@Controller('blogs')
export class BlogController {
constructor(private readonly blogService: BlogService) { }

Check warning on line 18 in src/modules/blog/blog.controller.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.controller.ts#L17-L18

Added lines #L17 - L18 were not covered by tests

@Post()
@Public()
@ApiOperation({ summary: 'Save new blog information' })
async add(@Body() blogDto: CreateBlogDto) {
return await this.blogService.add(blogDto);

Check warning on line 24 in src/modules/blog/blog.controller.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.controller.ts#L23-L24

Added lines #L23 - L24 were not covered by tests
}

@Get()
@Public()
@ApiOperation({ summary: 'Get all blog saved' })
async getAll() {
return await this.blogService.getAll();

Check warning on line 31 in src/modules/blog/blog.controller.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.controller.ts#L30-L31

Added lines #L30 - L31 were not covered by tests
}

@Get(':slug')
@Public()
@ApiOperation({ summary: 'Get details for this one' })
async getBySlug(@Param('slug') slug: string) {
return await this.blogService.getBlogDetailsWithComments(slug);

Check warning on line 38 in src/modules/blog/blog.controller.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.controller.ts#L37-L38

Added lines #L37 - L38 were not covered by tests
}

}
15 changes: 15 additions & 0 deletions src/modules/blog/blog.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Blog } from './entities/blog.entity';
import { BlogController } from './blog.controller';
import { BlogService } from './blog.service';

Check warning on line 5 in src/modules/blog/blog.module.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.module.ts#L1-L5

Added lines #L1 - L5 were not covered by tests

@Module({
imports: [
TypeOrmModule.forFeature([Blog]),
],
controllers: [BlogController],
providers: [BlogService],
exports: [BlogService],
})
export class BlogModule { }

Check warning on line 15 in src/modules/blog/blog.module.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.module.ts#L15

Added line #L15 was not covered by tests
51 changes: 51 additions & 0 deletions src/modules/blog/blog.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Not, Repository } from 'typeorm';

Check warning on line 3 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L1-L3

Added lines #L1 - L3 were not covered by tests
import { _404 } from '../../common/constants/errors';
import { MailService } from '../mail/mail.service';
import { Blog } from './entities/blog.entity';

Check warning on line 6 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L6

Added line #L6 was not covered by tests
import { CreateBlogDto } from './dto/blog.dto';
import Slugify from 'slugify';
import slugify from 'slugify';

Check warning on line 9 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L9

Added line #L9 was not covered by tests

@Injectable()
export class BlogService {

Check warning on line 12 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L12

Added line #L12 was not covered by tests
constructor(
@InjectRepository(Blog)
private blogRepository: Repository<Blog>,

Check warning on line 15 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L15

Added line #L15 was not covered by tests

) { }

async add(blog: CreateBlogDto): Promise<Blog> {

Check warning on line 19 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L19

Added line #L19 was not covered by tests

const newBlog = this.blogRepository.create({

Check warning on line 21 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L21

Added line #L21 was not covered by tests
title: blog.title,
slug: slugify(blog.title, { lower: true }),
content: blog.content,
quote: blog.quote,
tags: blog.tags,
cover: blog.cover
});

return this.blogRepository.save(newBlog);

Check warning on line 30 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L30

Added line #L30 was not covered by tests

}

async getAll(): Promise<Blog[]> {
return await this.blogRepository.find()

Check warning on line 35 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L34-L35

Added lines #L34 - L35 were not covered by tests
}

async getBlogDetailsWithComments(slug: string): Promise<any> {
const blog = await this.blogRepository.findOne({ where: { slug }, relations: ['comments'] });

Check warning on line 39 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L38-L39

Added lines #L38 - L39 were not covered by tests

const last = await this.blogRepository.find({

Check warning on line 41 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L41

Added line #L41 was not covered by tests
where: { slug: Not(slug) },
take: 3, // Récupère les trois derniers blogs
order: {
createdAt: 'DESC', // Trie par date de création décroissante
},
});

return { blog, last }

Check warning on line 49 in src/modules/blog/blog.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/blog.service.ts#L49

Added line #L49 was not covered by tests
}
}
27 changes: 27 additions & 0 deletions src/modules/blog/dto/blog.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {

Check warning on line 1 in src/modules/blog/dto/blog.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/dto/blog.dto.ts#L1

Added line #L1 was not covered by tests
IsArray,
IsNotEmpty,
IsString
} from 'class-validator';

export class CreateBlogDto {

Check warning on line 7 in src/modules/blog/dto/blog.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/dto/blog.dto.ts#L7

Added line #L7 was not covered by tests

@IsNotEmpty()

Check warning on line 9 in src/modules/blog/dto/blog.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/dto/blog.dto.ts#L9

Added line #L9 was not covered by tests
@IsString()
title: string;

@IsNotEmpty()

Check warning on line 13 in src/modules/blog/dto/blog.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/dto/blog.dto.ts#L13

Added line #L13 was not covered by tests
@IsString()
cover: string;

@IsString()

Check warning on line 17 in src/modules/blog/dto/blog.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/dto/blog.dto.ts#L17

Added line #L17 was not covered by tests
quote?: string;

@IsNotEmpty()

Check warning on line 20 in src/modules/blog/dto/blog.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/dto/blog.dto.ts#L20

Added line #L20 was not covered by tests
@IsString()
content: string;

@IsArray()

Check warning on line 24 in src/modules/blog/dto/blog.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/dto/blog.dto.ts#L24

Added line #L24 was not covered by tests
@IsString({ each: true })
tags?: string[];
}
30 changes: 30 additions & 0 deletions src/modules/blog/entities/blog.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Comment } from 'src/modules/comment/entities/comment.entity';
import { BaseEntity } from '../../../db/base-entity';
import { Entity, Column, ManyToMany, JoinTable } from 'typeorm';

Check warning on line 3 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

@Entity()
export class Blog extends BaseEntity {

Check warning on line 6 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L6

Added line #L6 was not covered by tests

@Column({ nullable: false })

Check warning on line 8 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L8

Added line #L8 was not covered by tests
title: string;

@Column({ nullable: false, unique: true })

Check warning on line 11 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L11

Added line #L11 was not covered by tests
slug: string;

@Column({ nullable: true })

Check warning on line 14 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L14

Added line #L14 was not covered by tests
cover: string;

@Column({ nullable: true })

Check warning on line 17 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L17

Added line #L17 was not covered by tests
quote?: string;

@Column({ nullable: false })

Check warning on line 20 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L20

Added line #L20 was not covered by tests
content: string;

@Column('text', { array: true, default: '{}' })

Check warning on line 23 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L23

Added line #L23 was not covered by tests
tags?: string[];

@ManyToMany(() => Comment, comment => comment.blog)

Check warning on line 26 in src/modules/blog/entities/blog.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/blog/entities/blog.entity.ts#L26

Added line #L26 was not covered by tests
@JoinTable()
comments?: Comment[];

}
19 changes: 19 additions & 0 deletions src/modules/comment/entities/comment.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Blog } from 'src/modules/blog/entities/blog.entity';
import { BaseEntity } from '../../../db/base-entity';
import { Entity, Column, ManyToOne } from 'typeorm';

Check warning on line 3 in src/modules/comment/entities/comment.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/comment/entities/comment.entity.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

@Entity()
export class Comment extends BaseEntity {

Check warning on line 6 in src/modules/comment/entities/comment.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/comment/entities/comment.entity.ts#L6

Added line #L6 was not covered by tests

@Column({ nullable: false })

Check warning on line 8 in src/modules/comment/entities/comment.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/comment/entities/comment.entity.ts#L8

Added line #L8 was not covered by tests
fullname: string;

@Column({ nullable: true })

Check warning on line 11 in src/modules/comment/entities/comment.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/comment/entities/comment.entity.ts#L11

Added line #L11 was not covered by tests
email?: string;

@Column({ nullable: false })

Check warning on line 14 in src/modules/comment/entities/comment.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/comment/entities/comment.entity.ts#L14

Added line #L14 was not covered by tests
comment: string;

@ManyToOne(() => Blog, blog => blog.comments)

Check warning on line 17 in src/modules/comment/entities/comment.entity.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/comment/entities/comment.entity.ts#L17

Added line #L17 was not covered by tests
blog: Blog;
}
8 changes: 4 additions & 4 deletions src/modules/mail/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@Injectable()
export class MailService {
constructor(private mailerService: MailerService) {}
constructor(private mailerService: MailerService) { }

/**
* This method sends OTP email during registration
Expand All @@ -12,7 +12,7 @@
* @param token
*/
async sendOTPEmail(email: string, token: string): Promise<void> {
const url = `https://wiiqare-app.com/auth/confirm?token=${token}`;
const url = `https://app.wiiqare.com/auth/confirm?token=${token}`;

Check warning on line 15 in src/modules/mail/mail.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/mail/mail.service.ts#L15

Added line #L15 was not covered by tests

await this.mailerService.sendMail({
to: email,
Expand All @@ -34,7 +34,7 @@
* @param token
*/
async sendResetPasswordEmail(email: string, token: string): Promise<void> {
const resetUrl = `https://wiiqare-app.com/reset-password/${token}`;
const resetUrl = `https://app.wiiqare.com/reset-password/${token}`;

Check warning on line 37 in src/modules/mail/mail.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/mail/mail.service.ts#L37

Added line #L37 was not covered by tests

await this.mailerService.sendMail({
to: email,
Expand Down Expand Up @@ -76,7 +76,7 @@
email: string,
token: string,
): Promise<void> {
const verifyEmail = `https://wiiqare-app.com/register?email-verification=${token}`;
const verifyEmail = `https://app.wiiqare.com/register?email-verification=${token}`;

Check warning on line 79 in src/modules/mail/mail.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/mail/mail.service.ts#L79

Added line #L79 was not covered by tests

await this.mailerService.sendMail({
to: email,
Expand Down
30 changes: 30 additions & 0 deletions src/modules/smart-contract/dto/mint-voucher.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,34 @@

@IsNotEmpty()
secondVoucher: string;
}

export class PaymentWithoutStripe {
@IsNotEmpty()

Check warning on line 52 in src/modules/smart-contract/dto/mint-voucher.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/smart-contract/dto/mint-voucher.dto.ts#L51-L52

Added lines #L51 - L52 were not covered by tests
@IsString()
senderId: string

@IsNotEmpty()

Check warning on line 56 in src/modules/smart-contract/dto/mint-voucher.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/smart-contract/dto/mint-voucher.dto.ts#L56

Added line #L56 was not covered by tests
@IsString()
patientId: string

@IsNotEmpty()

Check warning on line 60 in src/modules/smart-contract/dto/mint-voucher.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/smart-contract/dto/mint-voucher.dto.ts#L60

Added line #L60 was not covered by tests
@IsNumber()
currencyPatientAmount: number

@IsNotEmpty()

Check warning on line 64 in src/modules/smart-contract/dto/mint-voucher.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/smart-contract/dto/mint-voucher.dto.ts#L64

Added line #L64 was not covered by tests
@IsString()
currencyPatient: string

@IsNotEmpty()

Check warning on line 68 in src/modules/smart-contract/dto/mint-voucher.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/smart-contract/dto/mint-voucher.dto.ts#L68

Added line #L68 was not covered by tests
@IsNumber()
currencyRate: number

@IsNotEmpty()

Check warning on line 72 in src/modules/smart-contract/dto/mint-voucher.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/smart-contract/dto/mint-voucher.dto.ts#L72

Added line #L72 was not covered by tests
@IsNumber()
senderAmount: number

@IsNotEmpty()

Check warning on line 76 in src/modules/smart-contract/dto/mint-voucher.dto.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/smart-contract/dto/mint-voucher.dto.ts#L76

Added line #L76 was not covered by tests
@IsString()
senderCurrency: string
}
Loading