Spaces:
Running
Running
File size: 1,958 Bytes
433085e f39e411 36d3d2c 433085e 95ffa6b 433085e 22f0230 ac9dbd5 f39e411 ac9dbd5 433085e f39e411 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e 22f0230 433085e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import { Request, Response, Router } from "express";
import { BaseController } from "../../../../lib/controllers/controller.base";
import { AdminsService } from "../services/admins.service";
import { createAdminSchema } from "../validations/create-admin.validation";
import {
bodyValidator,
paramsValidator,
} from "../../../../helpers/validation.helper";
import { asyncHandler } from "../../../../helpers/async-handler";
import { Prefix } from "../../../../lib/decorators/prefix.decorator";
@Prefix("/console/admins")
export class AdminsController extends BaseController {
private adminsService = new AdminsService();
setRoutes() {
this.router.get("/", asyncHandler(this.list));
this.router.get("/:id", paramsValidator("id"), asyncHandler(this.get));
this.router.post(
"/",
bodyValidator(createAdminSchema),
asyncHandler(this.create)
);
this.router.patch(
"/:id",
paramsValidator("id"),
bodyValidator(createAdminSchema),
asyncHandler(this.update)
);
this.router.delete(
"/:id",
paramsValidator("id"),
asyncHandler(this.delete)
);
}
list = (_, res: Response) => {
this.adminsService
.list({})
.then((result) => {
res.status(result.code).json(result);
})
.catch((err) => {
res.status(500).json(err);
});
};
get = async (req: Request, res: Response) => {
const data = await this.adminsService.get({
_id: req.params.id,
});
res.json(data);
};
create = async (req: Request, res: Response) => {
const data = await this.adminsService.create(req.body);
res.json(data);
};
update = async (req: Request, res: Response) => {
const data = await this.adminsService.update(req.params.id, req.body);
res.json(data);
};
delete = async (req: Request, res: Response) => {
const data = await this.adminsService.remove(req.params.id);
res.json(data);
};
}
|