add main disease
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { MainDisease, Paging } from "entity";
|
import { DiseaseCategory, MainDisease, Paging } from "entity";
|
||||||
import { NextFunction, Response } from "express";
|
import { NextFunction, Response } from "express";
|
||||||
import { Request } from "express-jwt";
|
import { Request } from "express-jwt";
|
||||||
import Joi from "joi";
|
import Joi from "joi";
|
||||||
@ -15,6 +15,8 @@ const log: Logger<ILogObj> = new Logger({
|
|||||||
type: "pretty",
|
type: "pretty",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const diseaseCategoryValues = Object.values(DiseaseCategory);
|
||||||
|
|
||||||
export class MainDiseaseController {
|
export class MainDiseaseController {
|
||||||
static async list(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
static async list(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
/*
|
/*
|
||||||
@ -82,6 +84,10 @@ export class MainDiseaseController {
|
|||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
name: Joi.string().max(128).required().label("Name"),
|
name: Joi.string().max(128).required().label("Name"),
|
||||||
status: Joi.string().required().label("Status"),
|
status: Joi.string().required().label("Status"),
|
||||||
|
category: Joi.string()
|
||||||
|
.valid(...diseaseCategoryValues)
|
||||||
|
.required()
|
||||||
|
.label("Category"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
@ -93,6 +99,7 @@ export class MainDiseaseController {
|
|||||||
let entity = new MainDisease();
|
let entity = new MainDisease();
|
||||||
entity.name = param.name;
|
entity.name = param.name;
|
||||||
entity.status = param.status;
|
entity.status = param.status;
|
||||||
|
entity.category = param.category;
|
||||||
entity.created_by = req.auth.data.name;
|
entity.created_by = req.auth.data.name;
|
||||||
entity.updated_by = req.auth.data.name;
|
entity.updated_by = req.auth.data.name;
|
||||||
await queryRunner.manager.save(entity);
|
await queryRunner.manager.save(entity);
|
||||||
@ -152,6 +159,10 @@ export class MainDiseaseController {
|
|||||||
id: Joi.string().uuid().required().label("Main Disease ID"),
|
id: Joi.string().uuid().required().label("Main Disease ID"),
|
||||||
name: Joi.string().max(128).required().label("Name"),
|
name: Joi.string().max(128).required().label("Name"),
|
||||||
status: Joi.string().required().label("Status"),
|
status: Joi.string().required().label("Status"),
|
||||||
|
category: Joi.string()
|
||||||
|
.valid(...diseaseCategoryValues)
|
||||||
|
.required()
|
||||||
|
.label("Category"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
@ -166,6 +177,7 @@ export class MainDiseaseController {
|
|||||||
|
|
||||||
entity.name = param.name;
|
entity.name = param.name;
|
||||||
entity.status = param.status;
|
entity.status = param.status;
|
||||||
|
entity.category = param.category;
|
||||||
entity.updated_by = req.auth.data.name;
|
entity.updated_by = req.auth.data.name;
|
||||||
await queryRunner.manager.save(entity);
|
await queryRunner.manager.save(entity);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user