Added users entity; formatted all files
This commit is contained in:
@@ -1,50 +1,60 @@
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post, Put } 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 {
|
||||
constructor(
|
||||
@Inject(EntryService)
|
||||
private readonly entryService: EntryService
|
||||
) {}
|
||||
constructor(
|
||||
@Inject(EntryService)
|
||||
private readonly entryService: EntryService,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
async saveEntry(@Body() entry: EntryDTO): Promise<string | undefined> {
|
||||
return (await this.entryService.save(entry)).uuid;
|
||||
}
|
||||
|
||||
@Post()
|
||||
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;
|
||||
}
|
||||
|
||||
@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()
|
||||
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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
@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