Skip to content

Commit

Permalink
feat: 🎸 add patch api and add order by created_at
Browse files Browse the repository at this point in the history
  • Loading branch information
yeukfei02 committed Apr 25, 2022
1 parent cc906f0 commit 8e3dabb
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 0 deletions.
18 changes: 18 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ async function createLocations() {

const users = await prisma.users.findMany({
take: 50,
orderBy: {
created_at: 'desc',
},
});

for (let index = 0; index < 50; index++) {
Expand All @@ -78,6 +81,9 @@ async function createPosts() {

const users = await prisma.users.findMany({
take: 100,
orderBy: {
created_at: 'desc',
},
});

for (let index = 0; index < 100; index++) {
Expand All @@ -103,6 +109,9 @@ async function createTags() {

const posts = await prisma.post.findMany({
take: 20,
orderBy: {
created_at: 'desc',
},
});

for (let index = 0; index < 20; index++) {
Expand All @@ -125,9 +134,15 @@ async function createComments() {

const users = await prisma.users.findMany({
take: 100,
orderBy: {
created_at: 'desc',
},
});
const posts = await prisma.post.findMany({
take: 100,
orderBy: {
created_at: 'desc',
},
});

for (let index = 0; index < 100; index++) {
Expand All @@ -152,6 +167,9 @@ async function createTodos() {

const users = await prisma.users.findMany({
take: 100,
orderBy: {
created_at: 'desc',
},
});

for (let index = 0; index < 100; index++) {
Expand Down
20 changes: 20 additions & 0 deletions src/comment/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Post,
Body,
Put,
Patch,
Param,
Delete,
Query,
Expand Down Expand Up @@ -129,6 +130,25 @@ export class CommentController {
return response;
}

@Patch('/:id')
@ApiResponse({
status: 200,
description: 'Successful response',
type: UpdateCommentByIdResponse,
})
async patchCommentById(
@Param('id') id: string,
@Body() updateCommentDto: UpdateCommentDto,
): Promise<any> {
const comment = await this.commentService.updateCommentById(
id,
updateCommentDto,
);

const response = { message: 'updateCommentById', comment: comment };
return response;
}

@Delete('/:id')
@ApiResponse({
status: 200,
Expand Down
6 changes: 6 additions & 0 deletions src/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class CommentService {
},
skip: perPageInt * (pageInt - 1),
take: perPageInt,
orderBy: {
created_at: 'desc',
},
});

if (usersId) {
Expand All @@ -57,6 +60,9 @@ export class CommentService {
},
skip: perPageInt * (pageInt - 1),
take: perPageInt,
orderBy: {
created_at: 'desc',
},
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/location/location.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export class LocationService {
},
skip: perPageInt * (pageInt - 1),
take: perPageInt,
orderBy: {
created_at: 'desc',
},
});

if (usersId) {
Expand All @@ -49,6 +52,9 @@ export class LocationService {
},
skip: perPageInt * (pageInt - 1),
take: perPageInt,
orderBy: {
created_at: 'desc',
},
});
}

Expand Down
17 changes: 17 additions & 0 deletions src/post/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Post,
Get,
Put,
Patch,
Delete,
Body,
Param,
Expand Down Expand Up @@ -120,6 +121,22 @@ export class PostController {
return response;
}

@Patch('/:id')
@ApiResponse({
status: 200,
description: 'Successful response',
type: UpdatePostByIdResponse,
})
async patchPostById(
@Param('id') id: string,
@Body() updatePostDto: UpdatePostDto,
): Promise<any> {
const post = await this.postService.updatePostById(id, updatePostDto);

const response = { message: 'updatePostById', post: post };
return response;
}

@Delete('/:id')
@ApiResponse({
status: 200,
Expand Down
6 changes: 6 additions & 0 deletions src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class PostService {
},
skip: perPage * (page - 1),
take: perPage,
orderBy: {
created_at: 'desc',
},
});

if (usersId) {
Expand All @@ -57,6 +60,9 @@ export class PostService {
},
skip: perPage * (page - 1),
take: perPage,
orderBy: {
created_at: 'desc',
},
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/quote/quote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ export class QuoteService {
const quotes = await this.prisma.quote.findMany({
skip: perPageInt * (pageInt - 1),
take: perPageInt,
orderBy: {
created_at: 'desc',
},
});
return quotes;
}

async getRandomQuote(): Promise<quote> {
const quotes = await this.prisma.quote.findMany({
take: 100,
orderBy: {
created_at: 'desc',
},
});

const quote = _.sample(quotes);
Expand Down
6 changes: 6 additions & 0 deletions src/tag/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class TagService {
},
skip: perPage * (page - 1),
take: perPage,
orderBy: {
created_at: 'desc',
},
});

if (postId) {
Expand All @@ -39,6 +42,9 @@ export class TagService {
},
skip: perPage * (page - 1),
take: perPage,
orderBy: {
created_at: 'desc',
},
});
}

Expand Down
17 changes: 17 additions & 0 deletions src/todo/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Post,
Get,
Put,
Patch,
Delete,
Body,
Param,
Expand Down Expand Up @@ -120,6 +121,22 @@ export class TodoController {
return response;
}

@Patch('/:id')
@ApiResponse({
status: 200,
description: 'Successful response',
type: UpdateTodoByIdResponse,
})
async patchTodoById(
@Param('id') id: string,
@Body() updateTodoDto: UpdateTodoDto,
): Promise<any> {
const todo = await this.todoService.updateTodoById(id, updateTodoDto);

const response = { message: 'updateTodoById', todo: todo };
return response;
}

@Delete('/:id')
@ApiResponse({
status: 200,
Expand Down
6 changes: 6 additions & 0 deletions src/todo/todo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class TodoService {
let todos = await this.prisma.todo.findMany({
skip: perPage * (page - 1),
take: perPage,
orderBy: {
created_at: 'desc',
},
});

if (usersId) {
Expand All @@ -40,6 +43,9 @@ export class TodoService {
},
skip: perPage * (page - 1),
take: perPage,
orderBy: {
created_at: 'desc',
},
});
}

Expand Down
17 changes: 17 additions & 0 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Post,
Get,
Put,
Patch,
Delete,
Body,
Param,
Expand Down Expand Up @@ -112,6 +113,22 @@ export class UserController {
return response;
}

@Patch('/:id')
@ApiResponse({
status: 200,
description: 'Successful response',
type: UpdateUserByIdResponse,
})
async patchUserById(
@Param('id') id: string,
@Body() updateUserDto: UpdateUserDto,
): Promise<any> {
const user = await this.userService.updateUserById(id, updateUserDto);

const response = { message: 'updateUserById', user: user };
return response;
}

@Delete('/:id')
@ApiResponse({
status: 200,
Expand Down
3 changes: 3 additions & 0 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export class UserService {
},
skip: perPage * (page - 1),
take: perPage,
orderBy: {
created_at: 'desc',
},
});
return users;
}
Expand Down

0 comments on commit 8e3dabb

Please sign in to comment.