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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import { Paging } from "entity";
|
||||
import CommonHelper from "../helpers/common";
|
||||
import * as fastcsv from 'fast-csv';
|
||||
import dayjs from "dayjs";
|
||||
import { Suco } from "entity";
|
||||
import { Suco, Administrativu } from "entity";
|
||||
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[SucoController]', type: 'pretty' });
|
||||
|
||||
@ -76,11 +76,11 @@ export class SucoController {
|
||||
col_any_like: ['name']
|
||||
});
|
||||
|
||||
const res_count = repo.createQueryBuilder()
|
||||
const res_count = repo.createQueryBuilder("Suco")
|
||||
.where(whereAttr, whereVal);
|
||||
const res_list = repo.createQueryBuilder()
|
||||
const res_list = repo.createQueryBuilder("Suco")
|
||||
.where(whereAttr, whereVal)
|
||||
.orderBy(param.order_field, param.order_direction)
|
||||
.orderBy("Suco." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(param.limit);
|
||||
|
||||
@ -169,15 +169,15 @@ export class SucoController {
|
||||
const fetchAndWrite = async (page: any) => {
|
||||
const offset = (page - 1) * limit
|
||||
|
||||
const data = await repo.createQueryBuilder()
|
||||
const data = await repo.createQueryBuilder("Suco")
|
||||
.where(whereAttr, whereVal)
|
||||
.select([
|
||||
'id',
|
||||
'code',
|
||||
'name',
|
||||
'status',
|
||||
'created_at'])
|
||||
.orderBy(param.order_field, param.order_direction)
|
||||
'Suco.id',
|
||||
'Suco.code',
|
||||
'Suco.name',
|
||||
'Suco.status',
|
||||
'Suco.created_at'])
|
||||
.orderBy("Suco." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(limit).getRawMany();
|
||||
|
||||
@ -227,14 +227,18 @@ export class SucoController {
|
||||
code: Joi.string().max(128).required().label('Code'),
|
||||
name: Joi.string().max(256).required().label('Name'),
|
||||
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()
|
||||
data.code = param.code
|
||||
data.name = param.name
|
||||
data.status = param.status
|
||||
data.administrativu = administrativu
|
||||
|
||||
await OrmHelper.DB.manager.save(data);
|
||||
|
||||
@ -278,20 +282,24 @@ export class SucoController {
|
||||
code: Joi.string().max(128).required().label('Code'),
|
||||
name: Joi.string().max(256).required().label('Name'),
|
||||
status: Joi.string().required().label('Status'),
|
||||
administrativu_id: Joi.string().uuid().required().label('Administrativu'),
|
||||
});
|
||||
|
||||
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 data = await repo.findOneBy({ id: param.id });
|
||||
|
||||
if (data != null) {
|
||||
const administrativu = await OrmHelper.DB.getRepository(Administrativu).findOneByOrFail({ id: param.administrativu_id });
|
||||
|
||||
data.code = param.code
|
||||
data.name = param.name
|
||||
data.status = param.status
|
||||
data.administrativu = administrativu
|
||||
|
||||
await repo.save(data);
|
||||
|
||||
|
||||
@ -81,32 +81,41 @@ export default class CommonHelper {
|
||||
let fr = param.filter[p]
|
||||
|
||||
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)) {
|
||||
let found = false;
|
||||
if (fr['from']) {
|
||||
whereAttrPre.push(p + " >= :" + p + '_from');
|
||||
whereAttrPre.push(columnName + " >= :" + p + '_from');
|
||||
whereVal[p + '_from'] = fr['from'];
|
||||
found = true;
|
||||
}
|
||||
if (fr['to']) {
|
||||
whereAttrPre.push(p + " <= :" + p + '_to');
|
||||
whereAttrPre.push(columnName + " <= :" + p + '_to');
|
||||
whereVal[p + '_to'] = fr['to'];
|
||||
found = true;
|
||||
}
|
||||
if (fr['like']) {
|
||||
whereAttrPre.push('LOWER(' + p + ') like :' + p + '_like');
|
||||
whereAttrPre.push('LOWER(' + columnName + ') like :' + p + '_like');
|
||||
whereVal[p + '_like'] = '%' + fr['like'].toLowerCase() + '%';;
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
whereAttrPre.push("LOWER(" + p + ") = :" + p);
|
||||
whereAttrPre.push("LOWER(" + columnName + ") = :" + p);
|
||||
f = f.toLowerCase();
|
||||
|
||||
whereVal[p] = f;
|
||||
}
|
||||
} else {//uuid only
|
||||
whereAttrPre.push(p + " = :" + p);
|
||||
whereAttrPre.push(columnName + " = :" + p);
|
||||
whereVal[p] = f;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user