-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e112a93
commit 4acb1a3
Showing
3 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { Controller, Get, Query } from '@nestjs/common'; | ||
import { session_userprofile } from '@prisma/client'; | ||
import { GetUser } from 'src/common/decorators/get-user.decorator'; | ||
import { PlannerRequestDtoDefault } from 'src/common/interfaces/dto/planner/planner.request.dto'; | ||
import { PlannersService } from './planners.service'; | ||
|
||
@Controller('planners') | ||
export class PlannersController {} | ||
@Controller('users/:id/planners') | ||
export class PlannersController { | ||
constructor(private readonly plannersService: PlannersService) {} | ||
|
||
@Get() | ||
async getPlanners( | ||
@Query() query: PlannerRequestDtoDefault, | ||
@GetUser() user: session_userprofile, | ||
) { | ||
const planners = await this.plannersService.getPlannerByUser(query, user); | ||
return planners; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { session_userprofile } from '@prisma/client'; | ||
import { PlannerRepository } from 'src/prisma/repositories/planner.repository'; | ||
|
||
@Injectable() | ||
export class PlannersService {} | ||
export class PlannersService { | ||
constructor(private readonly plannerRepository: PlannerRepository) {} | ||
|
||
public async getPlannerByUser( | ||
query: PlannerRequestDTODefault, | ||
user: session_userprofile, | ||
) { | ||
return await this.plannerRepository.getPlannerByUser(query, user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { session_userprofile } from '@prisma/client'; | ||
import { PlannerRequestDtoDefault } from 'src/common/interfaces/dto/planner/planner.request.dto'; | ||
import { orderFilter } from 'src/common/utils/search.utils'; | ||
import { PrismaService } from '../prisma.service'; | ||
|
||
@Injectable() | ||
export class PlannerRepository { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
public async getPlannerByUser( | ||
query: PlannerRequestDtoDefault, | ||
user: session_userprofile, | ||
) { | ||
return await this.prisma.planner_planner.findMany({ | ||
where: { | ||
user_id: user.id, | ||
}, | ||
orderBy: orderFilter(query.order), | ||
skip: query.offset, | ||
take: query.limit, | ||
}); | ||
} | ||
} |