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

82 lines
1.9 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 UsersService from "@Services/UsersService/UsersService";
import { Service } from "typedi";
// import { IsNotEmpty, IsString, IsUUID } from "class-validator";
// class Params {
// @IsString()
// @IsNotEmpty()
// @IsUUID()
// public uuid!: string;
// }
@Controller()
@Service()
export default class UsersController extends ApiController {
constructor(private usersService: UsersService) {
super();
}
/**
* @description Get all users
* @returns IUser[] list of users
*/
@Get("/api/users")
protected async get(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.usersService.get());
}
/**
* @description Create a new user
* @returns IUser created
*/
@Post("/api/users")
protected async post(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.usersService.create());
}
/**
* @description Modify a specific user by uid
* @returns IUser modified
*/
@Put("/api/users/:uid")
protected async put(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.usersService.put());
}
/**
* @description Get a specific user by uid
* @returns IUser
*/
@Get("/api/users/:uid")
protected async getOneByUid(req: Request, response: Response) {
try {
// TODO
} catch (error) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.usersService.getByUid("uid"));
}
}