generated from Xen0Xys/NestJS-Template
-
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
Showing
5 changed files
with
66 additions
and
1 deletion.
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
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,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; | ||
} |
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,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(); | ||
} | ||
} |
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,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{} |
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,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 | ||
} | ||
}); | ||
} | ||
} |