Skip to content

Commit

Permalink
feat: add basics for planner
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan020313 committed Jan 20, 2024
1 parent e112a93 commit 4acb1a3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/modules/planners/planners.controller.ts
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;
}
}
13 changes: 12 additions & 1 deletion src/modules/planners/planners.service.ts
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);
}
}
24 changes: 24 additions & 0 deletions src/prisma/repositories/planner.repository.ts
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,
});
}
}

0 comments on commit 4acb1a3

Please sign in to comment.