Created all initial routes for entries data entity
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Body, Controller, Delete, Inject, Param, Post } from '@nestjs/common';
|
||||
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 {
|
||||
@@ -9,14 +10,41 @@ export class EntriesController {
|
||||
private readonly entryService: EntryService
|
||||
) {}
|
||||
|
||||
|
||||
@Post()
|
||||
async saveEntry(@Body() entry: EntryDTO) {
|
||||
async saveEntry(@Body() entry: EntryDTO): Promise<string | undefined> {
|
||||
return (await this.entryService.save(entry)).uuid
|
||||
}
|
||||
|
||||
@Put(":uuid")
|
||||
async updateEntry(@Param("uuid") uuid: string, @Body() entry: EntryDTO): Promise<string | undefined> {
|
||||
return (await this.entryService.updateByUuid(uuid, entry)).uuid
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<Entry[]>
|
||||
{
|
||||
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<Entry | null> {
|
||||
return await this.entryService.findOneByUuid(uuid)
|
||||
}
|
||||
|
||||
@Delete(":uuid")
|
||||
async softDelete(@Param("uuid") uuid: string): Promise<void>
|
||||
{
|
||||
await this.entryService.softDeleteByUuid(uuid)
|
||||
}
|
||||
|
||||
@Put("/restore/:uuid")
|
||||
async restoreSoftDeleted(@Param("uuid") uuid: string): Promise<Entry | null> {
|
||||
return await this.entryService.restoreDeletedByUuid(uuid)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user