Skip to content

Commit

Permalink
✨ Add tip of the day
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jan 4, 2024
1 parent 606a716 commit 1ccbe33
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {ConfigModule} from "@nestjs/config";
import {UsersModule} from "./users/users.module";
import {VerificationCodesModule} from "./verification-codes/verification-codes.module";
import {TodosModule} from "./todos/todos.module";
import {TipsModule} from "./tips/tips.module";

@Module({
imports: [AuthModule, VersionModule, ConfigModule.forRoot({isGlobal: true}), UsersModule, VerificationCodesModule, TodosModule],
imports: [AuthModule, VersionModule, ConfigModule.forRoot({isGlobal: true}), UsersModule, VerificationCodesModule, TodosModule, TipsModule],
})
export class AppModule{}
13 changes: 13 additions & 0 deletions src/tips/models/entities/tip.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Tips} from "@prisma/client";
import {ApiProperty} from "@nestjs/swagger";

export class TipEntity implements Tips{
@ApiProperty()
id: number;
@ApiProperty()
tips: string;
@ApiProperty()
author: string;
@ApiProperty()
order: number;
}
20 changes: 20 additions & 0 deletions src/tips/tips.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Controller, Get, HttpStatus, UseGuards} from "@nestjs/common";
import {ApiBearerAuth, ApiResponse, ApiTags} from "@nestjs/swagger";
import {AtGuard} from "../auth/guards/at.guard";
import {TipsService} from "./tips.service";
import {TipEntity} from "./models/entities/tip.entity";

@Controller("tips")
@ApiTags("Tips")
export class TipsController{
constructor(private readonly tipsService: TipsService){}

@Get("tod")
@UseGuards(AtGuard)
@ApiBearerAuth()
@ApiResponse({status: HttpStatus.OK, description: "Returns the tip of the day", type: TipEntity})
@ApiResponse({status: HttpStatus.NOT_FOUND, description: "No tip found for today"})
async getTipOfTheDay(): Promise<TipEntity>{
return await this.tipsService.getTipOfTheDay();
}
}
12 changes: 12 additions & 0 deletions src/tips/tips.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Module} from "@nestjs/common";
import {TipsService} from "./tips.service";
import {TipsController} from "./tips.controller";
import {ServicesModule} from "../services/services.module";
import {UsersModule} from "../users/users.module";

@Module({
controllers: [TipsController],
providers: [TipsService],
imports: [ServicesModule, UsersModule]
})
export class TipsModule{}
19 changes: 19 additions & 0 deletions src/tips/tips.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Injectable} from "@nestjs/common";
import {PrismaService} from "../services/prisma.service";

@Injectable()
export class TipsService{

constructor(
private readonly prismaService: PrismaService
){}

async getTipOfTheDay(){
const day = new Date().getDay();
return this.prismaService.tips.findFirst({
where: {
order: day
}
});
}
}

0 comments on commit 1ccbe33

Please sign in to comment.