update
This commit is contained in:
@ -9,7 +9,7 @@ import { Paging } from "entity";
|
||||
import CommonHelper from "../helpers/common";
|
||||
import * as fastcsv from 'fast-csv';
|
||||
import dayjs from "dayjs";
|
||||
import { Administrativu } from "entity";
|
||||
import { Administrativu, Munisipo } from "entity";
|
||||
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[AdministrativuController]', type: 'pretty' });
|
||||
|
||||
@ -76,11 +76,11 @@ export class AdministrativuController {
|
||||
col_any_like: ['name']
|
||||
});
|
||||
|
||||
const res_count = repo.createQueryBuilder()
|
||||
const res_count = repo.createQueryBuilder("Administrativu")
|
||||
.where(whereAttr, whereVal);
|
||||
const res_list = repo.createQueryBuilder()
|
||||
const res_list = repo.createQueryBuilder("Administrativu")
|
||||
.where(whereAttr, whereVal)
|
||||
.orderBy(param.order_field, param.order_direction)
|
||||
.orderBy("Administrativu." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(param.limit);
|
||||
|
||||
@ -169,15 +169,15 @@ export class AdministrativuController {
|
||||
const fetchAndWrite = async (page: any) => {
|
||||
const offset = (page - 1) * limit
|
||||
|
||||
const data = await repo.createQueryBuilder()
|
||||
const data = await repo.createQueryBuilder("Administrativu")
|
||||
.where(whereAttr, whereVal)
|
||||
.select([
|
||||
'id',
|
||||
'code',
|
||||
'name',
|
||||
'status',
|
||||
'created_at'])
|
||||
.orderBy(param.order_field, param.order_direction)
|
||||
'Administrativu.id',
|
||||
'Administrativu.code',
|
||||
'Administrativu.name',
|
||||
'Administrativu.status',
|
||||
'Administrativu.created_at'])
|
||||
.orderBy("Administrativu." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(limit).getRawMany();
|
||||
|
||||
@ -227,14 +227,18 @@ export class AdministrativuController {
|
||||
code: Joi.string().max(128).required().label('Code'),
|
||||
name: Joi.string().max(256).required().label('Name'),
|
||||
status: Joi.string().required().label('Status'),
|
||||
munisipo_id: Joi.string().uuid().required().label('Munisipo'),
|
||||
});
|
||||
|
||||
const param: Administrativu = await schema.validateAsync(req.body);
|
||||
const param: any = await schema.validateAsync(req.body);
|
||||
|
||||
const munisipo = await OrmHelper.DB.getRepository(Munisipo).findOneByOrFail({ id: param.munisipo_id });
|
||||
|
||||
const data = new Administrativu()
|
||||
data.code = param.code
|
||||
data.name = param.name
|
||||
data.status = param.status
|
||||
data.munisipo = munisipo
|
||||
|
||||
await OrmHelper.DB.manager.save(data);
|
||||
|
||||
@ -278,20 +282,24 @@ export class AdministrativuController {
|
||||
code: Joi.string().max(128).required().label('Code'),
|
||||
name: Joi.string().max(256).required().label('Name'),
|
||||
status: Joi.string().required().label('Status'),
|
||||
munisipo_id: Joi.string().uuid().required().label('Munisipo'),
|
||||
});
|
||||
|
||||
req.body.id = req.params['id'];
|
||||
|
||||
const param: Administrativu = await schema.validateAsync(req.body);
|
||||
const param: any = await schema.validateAsync(req.body);
|
||||
|
||||
const repo = OrmHelper.DB.getRepository(Administrativu);
|
||||
|
||||
const data = await repo.findOneBy({ id: param.id });
|
||||
|
||||
if (data != null) {
|
||||
const munisipo = await OrmHelper.DB.getRepository(Munisipo).findOneByOrFail({ id: param.munisipo_id });
|
||||
|
||||
data.code = param.code
|
||||
data.name = param.name
|
||||
data.status = param.status
|
||||
data.munisipo = munisipo
|
||||
|
||||
await repo.save(data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user