Skip to content

Commit

Permalink
Add module Blog (#106)
Browse files Browse the repository at this point in the history
* KYC save data

* KYC save his data

* Module to check KYC field

* Module to check KYC field

* Add Waiting List module

* Module for waiting

* fix tests

* Finished Waiting list

* Finished contact form

* Finish module for blog

---------

Co-authored-by: Abhishek Shandilya <[email protected]>
  • Loading branch information
Frdrcpeter007 and abhishandilya authored Nov 7, 2023
1 parent fd1b50f commit 4e59310
Show file tree
Hide file tree
Showing 10 changed files with 9,731 additions and 13,268 deletions.
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 { SavingModule } from './modules/saving/saving.module';
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';

@Module({
imports: [
Expand Down Expand Up @@ -60,6 +61,7 @@ import { ContactModule } from './modules/contact/contact.module';
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 {
Body,
Controller,
Get,
Param,
Post
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
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';
import slugify from 'slugify';

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

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

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

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

}
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';

@Module({
imports: [
TypeOrmModule.forFeature([Blog]),
],
controllers: [BlogController],
providers: [BlogService],
exports: [BlogService],
})
export class BlogModule { }
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';
import { _404 } from '../../common/constants/errors';
import { MailService } from '../mail/mail.service';
import { Blog } from './entities/blog.entity';
import { CreateBlogDto } from './dto/blog.dto';
import Slugify from 'slugify';
import slugify from 'slugify';

@Injectable()
export class BlogService {
constructor(
@InjectRepository(Blog)
private blogRepository: Repository<Blog>,

) { }

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

const newBlog = this.blogRepository.create({
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);

}

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

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

const last = await this.blogRepository.find({
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 }
}
}
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 {
IsArray,
IsNotEmpty,
IsString
} from 'class-validator';

export class CreateBlogDto {

@IsNotEmpty()
@IsString()
title: string;

@IsNotEmpty()
@IsString()
cover: string;

@IsString()
quote?: string;

@IsNotEmpty()
@IsString()
content: string;

@IsArray()
@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';

@Entity()
export class Blog extends BaseEntity {

@Column({ nullable: false })
title: string;

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

@Column({ nullable: true })
cover: string;

@Column({ nullable: true })
quote?: string;

@Column({ nullable: false })
content: string;

@Column('text', { array: true, default: '{}' })
tags?: string[];

@ManyToMany(() => Comment, comment => comment.blog)
@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';

@Entity()
export class Comment extends BaseEntity {

@Column({ nullable: false })
fullname: string;

@Column({ nullable: true })
email?: string;

@Column({ nullable: false })
comment: string;

@ManyToOne(() => Blog, blog => blog.comments)
blog: Blog;
}
Loading

0 comments on commit 4e59310

Please sign in to comment.