import { Body, Controller, Delete, Get, Inject, Param, Post, Put, } from '@nestjs/common'; import { EntryService } from './entries.service'; import { EntryDTO } from './entries.dto'; import { Entry } from './entries.entity'; @Controller('entries') export class EntriesController { constructor( @Inject(EntryService) private readonly entryService: EntryService, ) {} @Post() async saveEntry(@Body() entry: EntryDTO): Promise { return (await this.entryService.save(entry)).uuid; } @Put(':uuid') async updateEntry( @Param('uuid') uuid: string, @Body() entry: EntryDTO, ): Promise { return (await this.entryService.updateByUuid(uuid, entry)).uuid; } @Get() async findAll(): Promise { const entries = await this.entryService.findAll(); return entries.sort((a, b) => { return ( new Date(b.created_at as Date).getTime() - new Date(a.created_at as Date).getTime() ); }); } @Get(':uuid') async findOneByUuid(@Param('uuid') uuid: string): Promise { return await this.entryService.findOneByUuid(uuid); } @Delete(':uuid') async softDelete(@Param('uuid') uuid: string): Promise { await this.entryService.softDeleteByUuid(uuid); } @Put('/restore/:uuid') async restoreSoftDeleted(@Param('uuid') uuid: string): Promise { return await this.entryService.restoreDeletedByUuid(uuid); } }