update access token expired time

This commit is contained in:
2024-12-01 20:54:56 +07:00
parent f565b9b8b0
commit a93d4db18d
4 changed files with 110 additions and 36 deletions

View File

@ -29,7 +29,7 @@
}, },
"auth": { "auth": {
"refresh_token_lifetime_day": 30, "refresh_token_lifetime_day": 30,
"access_token_lifetime": 300, "access_token_lifetime": 86400,
"reset_password_url": "https://bri-dev.shiblysolution.id/reset-password/" "reset_password_url": "https://bri-dev.shiblysolution.id/reset-password/"
}, },
"service": { "service": {

View File

@ -29,7 +29,7 @@
}, },
"auth": { "auth": {
"refresh_token_lifetime_day": 30, "refresh_token_lifetime_day": 30,
"access_token_lifetime": 300, "access_token_lifetime": 86400,
"reset_password_url": "https://bri-dev.shiblysolution.id/reset-password/" "reset_password_url": "https://bri-dev.shiblysolution.id/reset-password/"
}, },
"service": { "service": {

View File

@ -73,44 +73,17 @@ export class UserController {
const offset = (param.page - 1) * param.limit const offset = (param.page - 1) * param.limit
let whereAttr = [];
let whereVal: any = {};
if (param.filter) { const { whereAttr, whereVal } = CommonHelper.handleFilter({
param.filter = JSON.parse(param.filter); filter: param.filter,
col_any_eq: ['email'],
let filter_any = false; col_any_like: ['name', 'username']
let filter_any_val = ''; });
for (let p in param.filter) {
let f = String(param.filter[p])
if (p != 'any') {
if (!validate(f)) {
whereAttr.push("LOWER(" + p + ") = :" + p);
f = f.toLowerCase();
} else {
whereAttr.push(p + " = :" + p);
}
whereVal[p] = f;
} else {
filter_any = true;
filter_any_val = f;
}
}
if (filter_any) {
whereAttr.push('(name like :filter_like or username like :filter_like or email = :filter) ');
whereVal['filter'] = filter_any_val
whereVal['filter_like'] = '%' + filter_any_val + '%'
}
}
const res_count = userRepository.createQueryBuilder() const res_count = userRepository.createQueryBuilder()
.where(whereAttr.join(' and '), whereVal); .where(whereAttr, whereVal);
const res_list = userRepository.createQueryBuilder() const res_list = userRepository.createQueryBuilder()
.where(whereAttr.join(' and '), whereVal) .where(whereAttr, whereVal)
.orderBy(param.order_field, param.order_direction) .orderBy(param.order_field, param.order_direction)
.offset(offset) .offset(offset)
.limit(param.limit); .limit(param.limit);

View File

@ -1,4 +1,5 @@
import { Logger, ILogObj } from 'tslog'; import { Logger, ILogObj } from 'tslog';
import { validate } from 'uuid';
const log: Logger<ILogObj> = new Logger({ name: '[CommonHelper]', type: 'pretty' }); const log: Logger<ILogObj> = new Logger({ name: '[CommonHelper]', type: 'pretty' });
@ -91,4 +92,104 @@ export default class CommonHelper {
return template return template
} }
static handleFilter(param: { filter: any, col_any_eq: string[], col_any_like: string[] }): any {
const whereAttrPre = [];
const whereVal: any = {};
if (param.filter) {
try {
param.filter = JSON.parse(param.filter);
let filter_any = false;
let filter_any_val = '';
for (let p in param.filter) {
let f = String(param.filter[p])
if (p != 'any') {
if (!validate(f)) {
whereAttrPre.push("LOWER(" + p + ") = :" + p);
f = f.toLowerCase();
} else {
whereAttrPre.push(p + " = :" + p);
}
whereVal[p] = f;
} else {
filter_any = true;
filter_any_val = f;
}
}
if (filter_any) {
let wtp = []
if (param.col_any_eq.length > 0) {
const eqr = [];
for (let c of param.col_any_eq) {
eqr.push('LOWER(' + c + ') = :filter_eq');
}
const eq = '(' + eqr.join(' or ') + ')';
wtp.push(eq);
}
if (param.col_any_like.length > 0) {
const liker = [];
for (let c of param.col_any_like) {
liker.push(c + ' like :filter_like');
}
const like = '(' + liker.join(' or ') + ')';
wtp.push(like);
}
whereAttrPre.push('(' + wtp.join(' or ') + ')');
if (param.col_any_eq.length > 0) {
whereVal['filter_eq'] = filter_any_val;
}
if (param.col_any_like.length > 0) {
whereVal['filter_like'] = '%' + filter_any_val + '%';
}
}
} catch (e: any) {
let wtp = []
if (param.col_any_eq.length > 0) {
const eqr = [];
for (let c of param.col_any_eq) {
eqr.push('LOWER(' + c + ') = :filter_eq');
}
const eq = '(' + eqr.join(' or ') + ')';
wtp.push(eq);
}
if (param.col_any_like.length > 0) {
const liker = [];
for (let c of param.col_any_like) {
liker.push(c + ' like :filter_like');
}
const like = '(' + liker.join(' or ') + ')';
wtp.push(like);
}
whereAttrPre.push('(' + wtp.join(' or ') + ')');
if (param.col_any_eq.length > 0) {
whereVal['filter_eq'] = param.filter.toLowerCase();
}
if (param.col_any_like.length > 0) {
whereVal['filter_like'] = '%' + param.filter + '%';
}
}
}
const whereAttr = whereAttrPre.join(' and ');
return { whereAttr, whereVal };
}
} }