update
This commit is contained in:
@ -9,7 +9,7 @@ import { Paging } from "entity";
|
|||||||
import CommonHelper from "../helpers/common";
|
import CommonHelper from "../helpers/common";
|
||||||
import * as fastcsv from 'fast-csv';
|
import * as fastcsv from 'fast-csv';
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { Administrativu } from "entity";
|
import { Administrativu, Munisipo } from "entity";
|
||||||
|
|
||||||
const log: Logger<ILogObj> = new Logger({ name: '[AdministrativuController]', type: 'pretty' });
|
const log: Logger<ILogObj> = new Logger({ name: '[AdministrativuController]', type: 'pretty' });
|
||||||
|
|
||||||
@ -76,11 +76,11 @@ export class AdministrativuController {
|
|||||||
col_any_like: ['name']
|
col_any_like: ['name']
|
||||||
});
|
});
|
||||||
|
|
||||||
const res_count = repo.createQueryBuilder()
|
const res_count = repo.createQueryBuilder("Administrativu")
|
||||||
.where(whereAttr, whereVal);
|
.where(whereAttr, whereVal);
|
||||||
const res_list = repo.createQueryBuilder()
|
const res_list = repo.createQueryBuilder("Administrativu")
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy("Administrativu." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(param.limit);
|
.limit(param.limit);
|
||||||
|
|
||||||
@ -169,15 +169,15 @@ export class AdministrativuController {
|
|||||||
const fetchAndWrite = async (page: any) => {
|
const fetchAndWrite = async (page: any) => {
|
||||||
const offset = (page - 1) * limit
|
const offset = (page - 1) * limit
|
||||||
|
|
||||||
const data = await repo.createQueryBuilder()
|
const data = await repo.createQueryBuilder("Administrativu")
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.select([
|
.select([
|
||||||
'id',
|
'Administrativu.id',
|
||||||
'code',
|
'Administrativu.code',
|
||||||
'name',
|
'Administrativu.name',
|
||||||
'status',
|
'Administrativu.status',
|
||||||
'created_at'])
|
'Administrativu.created_at'])
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy("Administrativu." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit).getRawMany();
|
.limit(limit).getRawMany();
|
||||||
|
|
||||||
@ -227,14 +227,18 @@ export class AdministrativuController {
|
|||||||
code: Joi.string().max(128).required().label('Code'),
|
code: Joi.string().max(128).required().label('Code'),
|
||||||
name: Joi.string().max(256).required().label('Name'),
|
name: Joi.string().max(256).required().label('Name'),
|
||||||
status: Joi.string().required().label('Status'),
|
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()
|
const data = new Administrativu()
|
||||||
data.code = param.code
|
data.code = param.code
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.munisipo = munisipo
|
||||||
|
|
||||||
await OrmHelper.DB.manager.save(data);
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
@ -278,20 +282,24 @@ export class AdministrativuController {
|
|||||||
code: Joi.string().max(128).required().label('Code'),
|
code: Joi.string().max(128).required().label('Code'),
|
||||||
name: Joi.string().max(256).required().label('Name'),
|
name: Joi.string().max(256).required().label('Name'),
|
||||||
status: Joi.string().required().label('Status'),
|
status: Joi.string().required().label('Status'),
|
||||||
|
munisipo_id: Joi.string().uuid().required().label('Munisipo'),
|
||||||
});
|
});
|
||||||
|
|
||||||
req.body.id = req.params['id'];
|
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 repo = OrmHelper.DB.getRepository(Administrativu);
|
||||||
|
|
||||||
const data = await repo.findOneBy({ id: param.id });
|
const data = await repo.findOneBy({ id: param.id });
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
const munisipo = await OrmHelper.DB.getRepository(Munisipo).findOneByOrFail({ id: param.munisipo_id });
|
||||||
|
|
||||||
data.code = param.code
|
data.code = param.code
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.munisipo = munisipo
|
||||||
|
|
||||||
await repo.save(data);
|
await repo.save(data);
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { Paging } from "entity";
|
|||||||
import CommonHelper from "../helpers/common";
|
import CommonHelper from "../helpers/common";
|
||||||
import * as fastcsv from 'fast-csv';
|
import * as fastcsv from 'fast-csv';
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { Aldeia } from "entity";
|
import { Aldeia, Suco } from "entity";
|
||||||
|
|
||||||
const log: Logger<ILogObj> = new Logger({ name: '[AldeiaController]', type: 'pretty' });
|
const log: Logger<ILogObj> = new Logger({ name: '[AldeiaController]', type: 'pretty' });
|
||||||
|
|
||||||
@ -76,11 +76,11 @@ export class AldeiaController {
|
|||||||
col_any_like: ['name']
|
col_any_like: ['name']
|
||||||
});
|
});
|
||||||
|
|
||||||
const res_count = repo.createQueryBuilder()
|
const res_count = repo.createQueryBuilder("Aldeia")
|
||||||
.where(whereAttr, whereVal);
|
.where(whereAttr, whereVal);
|
||||||
const res_list = repo.createQueryBuilder()
|
const res_list = repo.createQueryBuilder("Aldeia")
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy("Aldeia." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(param.limit);
|
.limit(param.limit);
|
||||||
|
|
||||||
@ -169,15 +169,15 @@ export class AldeiaController {
|
|||||||
const fetchAndWrite = async (page: any) => {
|
const fetchAndWrite = async (page: any) => {
|
||||||
const offset = (page - 1) * limit
|
const offset = (page - 1) * limit
|
||||||
|
|
||||||
const data = await repo.createQueryBuilder()
|
const data = await repo.createQueryBuilder("Aldeia")
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.select([
|
.select([
|
||||||
'id',
|
'Aldeia.id',
|
||||||
'code',
|
'Aldeia.code',
|
||||||
'name',
|
'Aldeia.name',
|
||||||
'status',
|
'Aldeia.status',
|
||||||
'created_at'])
|
'Aldeia.created_at'])
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy("Aldeia." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit).getRawMany();
|
.limit(limit).getRawMany();
|
||||||
|
|
||||||
@ -227,14 +227,18 @@ export class AldeiaController {
|
|||||||
code: Joi.string().max(128).required().label('Code'),
|
code: Joi.string().max(128).required().label('Code'),
|
||||||
name: Joi.string().max(256).required().label('Name'),
|
name: Joi.string().max(256).required().label('Name'),
|
||||||
status: Joi.string().required().label('Status'),
|
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()
|
const data = new Aldeia()
|
||||||
data.code = param.code
|
data.code = param.code
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.suco = suco
|
||||||
|
|
||||||
await OrmHelper.DB.manager.save(data);
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
@ -278,20 +282,24 @@ export class AldeiaController {
|
|||||||
code: Joi.string().max(128).required().label('Code'),
|
code: Joi.string().max(128).required().label('Code'),
|
||||||
name: Joi.string().max(256).required().label('Name'),
|
name: Joi.string().max(256).required().label('Name'),
|
||||||
status: Joi.string().required().label('Status'),
|
status: Joi.string().required().label('Status'),
|
||||||
|
suco_id: Joi.string().uuid().required().label('Suco'),
|
||||||
});
|
});
|
||||||
|
|
||||||
req.body.id = req.params['id'];
|
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 repo = OrmHelper.DB.getRepository(Aldeia);
|
||||||
|
|
||||||
const data = await repo.findOneBy({ id: param.id });
|
const data = await repo.findOneBy({ id: param.id });
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
const suco = await OrmHelper.DB.getRepository(Suco).findOneByOrFail({ id: param.suco_id });
|
||||||
|
|
||||||
data.code = param.code
|
data.code = param.code
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.suco = suco
|
||||||
|
|
||||||
await repo.save(data);
|
await repo.save(data);
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { Paging } from "entity";
|
|||||||
import CommonHelper from "../helpers/common";
|
import CommonHelper from "../helpers/common";
|
||||||
import * as fastcsv from 'fast-csv';
|
import * as fastcsv from 'fast-csv';
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { Suco } from "entity";
|
import { Suco, Administrativu } from "entity";
|
||||||
|
|
||||||
const log: Logger<ILogObj> = new Logger({ name: '[SucoController]', type: 'pretty' });
|
const log: Logger<ILogObj> = new Logger({ name: '[SucoController]', type: 'pretty' });
|
||||||
|
|
||||||
@ -76,11 +76,11 @@ export class SucoController {
|
|||||||
col_any_like: ['name']
|
col_any_like: ['name']
|
||||||
});
|
});
|
||||||
|
|
||||||
const res_count = repo.createQueryBuilder()
|
const res_count = repo.createQueryBuilder("Suco")
|
||||||
.where(whereAttr, whereVal);
|
.where(whereAttr, whereVal);
|
||||||
const res_list = repo.createQueryBuilder()
|
const res_list = repo.createQueryBuilder("Suco")
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy("Suco." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(param.limit);
|
.limit(param.limit);
|
||||||
|
|
||||||
@ -169,15 +169,15 @@ export class SucoController {
|
|||||||
const fetchAndWrite = async (page: any) => {
|
const fetchAndWrite = async (page: any) => {
|
||||||
const offset = (page - 1) * limit
|
const offset = (page - 1) * limit
|
||||||
|
|
||||||
const data = await repo.createQueryBuilder()
|
const data = await repo.createQueryBuilder("Suco")
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.select([
|
.select([
|
||||||
'id',
|
'Suco.id',
|
||||||
'code',
|
'Suco.code',
|
||||||
'name',
|
'Suco.name',
|
||||||
'status',
|
'Suco.status',
|
||||||
'created_at'])
|
'Suco.created_at'])
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy("Suco." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit).getRawMany();
|
.limit(limit).getRawMany();
|
||||||
|
|
||||||
@ -227,14 +227,18 @@ export class SucoController {
|
|||||||
code: Joi.string().max(128).required().label('Code'),
|
code: Joi.string().max(128).required().label('Code'),
|
||||||
name: Joi.string().max(256).required().label('Name'),
|
name: Joi.string().max(256).required().label('Name'),
|
||||||
status: Joi.string().required().label('Status'),
|
status: Joi.string().required().label('Status'),
|
||||||
|
administrativu_id: Joi.string().uuid().required().label('Administrativu'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const param: Suco = await schema.validateAsync(req.body);
|
const param: any = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
|
const administrativu = await OrmHelper.DB.getRepository(Administrativu).findOneByOrFail({ id: param.administrativu_id });
|
||||||
|
|
||||||
const data = new Suco()
|
const data = new Suco()
|
||||||
data.code = param.code
|
data.code = param.code
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.administrativu = administrativu
|
||||||
|
|
||||||
await OrmHelper.DB.manager.save(data);
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
@ -278,20 +282,24 @@ export class SucoController {
|
|||||||
code: Joi.string().max(128).required().label('Code'),
|
code: Joi.string().max(128).required().label('Code'),
|
||||||
name: Joi.string().max(256).required().label('Name'),
|
name: Joi.string().max(256).required().label('Name'),
|
||||||
status: Joi.string().required().label('Status'),
|
status: Joi.string().required().label('Status'),
|
||||||
|
administrativu_id: Joi.string().uuid().required().label('Administrativu'),
|
||||||
});
|
});
|
||||||
|
|
||||||
req.body.id = req.params['id'];
|
req.body.id = req.params['id'];
|
||||||
|
|
||||||
const param: Suco = await schema.validateAsync(req.body);
|
const param: any = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
const repo = OrmHelper.DB.getRepository(Suco);
|
const repo = OrmHelper.DB.getRepository(Suco);
|
||||||
|
|
||||||
const data = await repo.findOneBy({ id: param.id });
|
const data = await repo.findOneBy({ id: param.id });
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
const administrativu = await OrmHelper.DB.getRepository(Administrativu).findOneByOrFail({ id: param.administrativu_id });
|
||||||
|
|
||||||
data.code = param.code
|
data.code = param.code
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.administrativu = administrativu
|
||||||
|
|
||||||
await repo.save(data);
|
await repo.save(data);
|
||||||
|
|
||||||
|
|||||||
@ -81,32 +81,41 @@ export default class CommonHelper {
|
|||||||
let fr = param.filter[p]
|
let fr = param.filter[p]
|
||||||
|
|
||||||
if (p != 'any') {
|
if (p != 'any') {
|
||||||
|
// Map property names to database column names
|
||||||
|
// TypeORM uses camelCase for property names, but database uses snake_case
|
||||||
|
// For foreign keys, we need to use the actual database column name
|
||||||
|
let columnName = p;
|
||||||
|
// If it contains underscore, it's already snake_case, use it with quotes for PostgreSQL
|
||||||
|
if (p.includes('_')) {
|
||||||
|
columnName = '"' + p + '"';
|
||||||
|
}
|
||||||
|
|
||||||
if (!validate(f)) {
|
if (!validate(f)) {
|
||||||
let found = false;
|
let found = false;
|
||||||
if (fr['from']) {
|
if (fr['from']) {
|
||||||
whereAttrPre.push(p + " >= :" + p + '_from');
|
whereAttrPre.push(columnName + " >= :" + p + '_from');
|
||||||
whereVal[p + '_from'] = fr['from'];
|
whereVal[p + '_from'] = fr['from'];
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (fr['to']) {
|
if (fr['to']) {
|
||||||
whereAttrPre.push(p + " <= :" + p + '_to');
|
whereAttrPre.push(columnName + " <= :" + p + '_to');
|
||||||
whereVal[p + '_to'] = fr['to'];
|
whereVal[p + '_to'] = fr['to'];
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (fr['like']) {
|
if (fr['like']) {
|
||||||
whereAttrPre.push('LOWER(' + p + ') like :' + p + '_like');
|
whereAttrPre.push('LOWER(' + columnName + ') like :' + p + '_like');
|
||||||
whereVal[p + '_like'] = '%' + fr['like'].toLowerCase() + '%';;
|
whereVal[p + '_like'] = '%' + fr['like'].toLowerCase() + '%';;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
whereAttrPre.push("LOWER(" + p + ") = :" + p);
|
whereAttrPre.push("LOWER(" + columnName + ") = :" + p);
|
||||||
f = f.toLowerCase();
|
f = f.toLowerCase();
|
||||||
|
|
||||||
whereVal[p] = f;
|
whereVal[p] = f;
|
||||||
}
|
}
|
||||||
} else {//uuid only
|
} else {//uuid only
|
||||||
whereAttrPre.push(p + " = :" + p);
|
whereAttrPre.push(columnName + " = :" + p);
|
||||||
whereVal[p] = f;
|
whereVal[p] = f;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user