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 { Aldeia } from "entity";
|
||||
import { Aldeia, Suco } from "entity";
|
||||
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[AldeiaController]', type: 'pretty' });
|
||||
|
||||
@ -76,11 +76,11 @@ export class AldeiaController {
|
||||
col_any_like: ['name']
|
||||
});
|
||||
|
||||
const res_count = repo.createQueryBuilder()
|
||||
const res_count = repo.createQueryBuilder("Aldeia")
|
||||
.where(whereAttr, whereVal);
|
||||
const res_list = repo.createQueryBuilder()
|
||||
const res_list = repo.createQueryBuilder("Aldeia")
|
||||
.where(whereAttr, whereVal)
|
||||
.orderBy(param.order_field, param.order_direction)
|
||||
.orderBy("Aldeia." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(param.limit);
|
||||
|
||||
@ -169,15 +169,15 @@ export class AldeiaController {
|
||||
const fetchAndWrite = async (page: any) => {
|
||||
const offset = (page - 1) * limit
|
||||
|
||||
const data = await repo.createQueryBuilder()
|
||||
const data = await repo.createQueryBuilder("Aldeia")
|
||||
.where(whereAttr, whereVal)
|
||||
.select([
|
||||
'id',
|
||||
'code',
|
||||
'name',
|
||||
'status',
|
||||
'created_at'])
|
||||
.orderBy(param.order_field, param.order_direction)
|
||||
'Aldeia.id',
|
||||
'Aldeia.code',
|
||||
'Aldeia.name',
|
||||
'Aldeia.status',
|
||||
'Aldeia.created_at'])
|
||||
.orderBy("Aldeia." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(limit).getRawMany();
|
||||
|
||||
@ -227,14 +227,18 @@ export class AldeiaController {
|
||||
code: Joi.string().max(128).required().label('Code'),
|
||||
name: Joi.string().max(256).required().label('Name'),
|
||||
status: Joi.string().required().label('Status'),
|
||||
suco_id: Joi.string().uuid().required().label('Suco'),
|
||||
});
|
||||
|
||||
const param: Aldeia = await schema.validateAsync(req.body);
|
||||
const param: any = await schema.validateAsync(req.body);
|
||||
|
||||
const suco = await OrmHelper.DB.getRepository(Suco).findOneByOrFail({ id: param.suco_id });
|
||||
|
||||
const data = new Aldeia()
|
||||
data.code = param.code
|
||||
data.name = param.name
|
||||
data.status = param.status
|
||||
data.suco = suco
|
||||
|
||||
await OrmHelper.DB.manager.save(data);
|
||||
|
||||
@ -278,20 +282,24 @@ export class AldeiaController {
|
||||
code: Joi.string().max(128).required().label('Code'),
|
||||
name: Joi.string().max(256).required().label('Name'),
|
||||
status: Joi.string().required().label('Status'),
|
||||
suco_id: Joi.string().uuid().required().label('Suco'),
|
||||
});
|
||||
|
||||
req.body.id = req.params['id'];
|
||||
|
||||
const param: Aldeia = await schema.validateAsync(req.body);
|
||||
const param: any = await schema.validateAsync(req.body);
|
||||
|
||||
const repo = OrmHelper.DB.getRepository(Aldeia);
|
||||
|
||||
const data = await repo.findOneBy({ id: param.id });
|
||||
|
||||
if (data != null) {
|
||||
const suco = await OrmHelper.DB.getRepository(Suco).findOneByOrFail({ id: param.suco_id });
|
||||
|
||||
data.code = param.code
|
||||
data.name = param.name
|
||||
data.status = param.status
|
||||
data.suco = suco
|
||||
|
||||
await repo.save(data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user