lecoffre-back/src/app/api/DocumentsController.ts

82 lines
2.0 KiB
TypeScript

import { type Response, type Request } from "express";
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Service } from "typedi";
import DocumentsService from "@Services/DocumentsService/DocumentsService";
// import { IsNotEmpty, IsString, IsUUID } from "class-validator";
// class Params {
// @IsString()
// @IsNotEmpty()
// @IsUUID()
// public uuid!: string;
// }
@Controller()
@Service()
export default class DocumentsController extends ApiController {
constructor(private documentsService: DocumentsService) {
super();
}
/**
* @description Get all documents
* @returns IDocument[] list of documents
*/
@Get("/api/documents")
protected async get(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.documentsService.get());
}
/**
* @description Create a new document
* @returns IDocument created
*/
@Post("/api/documents")
protected async post(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.documentsService.create());
}
/**
* @description Modify a specific document by uid
* @returns IDocument modified
*/
@Put("/api/documents/:uid")
protected async put(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.documentsService.put());
}
/**
* @description Get a specific document by uid
* @returns IDocument
*/
@Get("/api/documents/:uid")
protected async getOneByUid(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.documentsService.getByUid("uid"));
}
}