55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { Response, Request } from "express";
|
|
import { Controller, Get } from "@ControllerPattern/index";
|
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
|
import DeedsService from "@Services/super-admin/DeedsService/DeedsService";
|
|
import { Service } from "typedi";
|
|
import { Deeds } from "@prisma/client";
|
|
import Deed from "le-coffre-resources/dist/SuperAdmin";
|
|
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
|
|
@Controller()
|
|
@Service()
|
|
export default class DeedsController extends ApiController {
|
|
constructor(private deedsService: DeedsService) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @description Get all deeds
|
|
* @returns IDeed[] list of deeds
|
|
*/
|
|
@Get("/api/v1/super-admin/deeds")
|
|
protected async get(req: Request, response: Response) {
|
|
try {
|
|
//get query
|
|
const query = JSON.parse(req.query["q"] as string);
|
|
//call service to get prisma entity
|
|
const prismaEntity: Deeds[] = await this.deedsService.get(query);
|
|
|
|
//Hydrate ressource with prisma entity
|
|
const deeds = ObjectHydrate.map<Deed>(Deed, prismaEntity, { strategy: "exposeAll" });
|
|
|
|
//success
|
|
this.httpSuccess(response, deeds);
|
|
} catch (error) {
|
|
this.httpBadRequest(response, error);
|
|
return;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @description Get a specific deed by uid
|
|
* @returns IDeed
|
|
*/
|
|
@Get("/api/v1/super-admin/deeds/:uid")
|
|
protected async getOneByUid(req: Request, response: Response) {
|
|
try {
|
|
// TODO
|
|
} catch (error) {
|
|
this.httpBadRequest(response, error);
|
|
return;
|
|
}
|
|
this.httpSuccess(response, await this.deedsService.getByUid("uid"));
|
|
}
|
|
}
|