Merge branch 'dev' into 5855-temporaryTable
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
205d79f0a6
|
@ -16,36 +16,51 @@ module.exports = Self => {
|
||||||
accessScopes: ['DEFAULT', 'read:multimedia']});
|
accessScopes: ['DEFAULT', 'read:multimedia']});
|
||||||
|
|
||||||
Self.renewToken = async function(ctx) {
|
Self.renewToken = async function(ctx) {
|
||||||
const {accessToken: token} = ctx.req;
|
|
||||||
|
|
||||||
const {courtesyTime} = await models.AccessTokenConfig.findOne({
|
|
||||||
fields: ['courtesyTime']
|
|
||||||
});
|
|
||||||
const isNotExceeded = await Self.validateToken(ctx);
|
|
||||||
if (isNotExceeded)
|
|
||||||
return token;
|
|
||||||
|
|
||||||
// Schedule to remove current token
|
|
||||||
setTimeout(async() => {
|
|
||||||
try {
|
|
||||||
const exists = await models.AccessToken.findById(token.id);
|
|
||||||
exists && await Self.logout(token.id);
|
|
||||||
} catch (err) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}, courtesyTime * 1000);
|
|
||||||
|
|
||||||
// Get scopes
|
|
||||||
|
|
||||||
let createTokenOptions = {};
|
let createTokenOptions = {};
|
||||||
const {scopes} = token;
|
let token; let isNotExceeded;
|
||||||
if (scopes)
|
try {
|
||||||
createTokenOptions = {scopes: [scopes[0]]};
|
token = ctx.req.accessToken;
|
||||||
// Create new accessToken
|
|
||||||
const user = await Self.findById(token.userId);
|
|
||||||
const accessToken = await user.accessTokens.create(createTokenOptions);
|
|
||||||
|
|
||||||
return {id: accessToken.id, ttl: accessToken.ttl};
|
const {courtesyTime} = await models.AccessTokenConfig.findOne({
|
||||||
|
fields: ['courtesyTime']
|
||||||
|
});
|
||||||
|
isNotExceeded = await Self.validateToken(ctx);
|
||||||
|
if (isNotExceeded)
|
||||||
|
return token;
|
||||||
|
|
||||||
|
// Schedule to remove current token
|
||||||
|
setTimeout(async() => {
|
||||||
|
let exists;
|
||||||
|
try {
|
||||||
|
exists = await models.AccessToken.findById(token.id);
|
||||||
|
exists && await Self.logout(token.id);
|
||||||
|
} catch (error) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(error);
|
||||||
|
const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, exists};
|
||||||
|
await handleError(body);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}, courtesyTime * 1000);
|
||||||
|
|
||||||
|
// Get scopes
|
||||||
|
const {scopes} = token;
|
||||||
|
if (scopes)
|
||||||
|
createTokenOptions = {scopes: [scopes[0]]};
|
||||||
|
// Create new accessToken
|
||||||
|
const user = await Self.findById(token.userId);
|
||||||
|
const accessToken = await user.accessTokens.create(createTokenOptions);
|
||||||
|
|
||||||
|
return {id: accessToken.id, ttl: accessToken.ttl};
|
||||||
|
} catch (error) {
|
||||||
|
const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, createTokenOptions, isNotExceeded};
|
||||||
|
await handleError(body);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function handleError(body, tag = 'renewToken') {
|
||||||
|
body = JSON.stringify(body);
|
||||||
|
await models.Application.rawSql('CALL util.debugAdd(?,?);', [tag, body]);
|
||||||
|
}
|
||||||
|
|
|
@ -61,4 +61,21 @@ describe('Renew Token', () => {
|
||||||
expect(error).toBeUndefined();
|
expect(error).toBeUndefined();
|
||||||
expect(response.id).toEqual(ctx.req.accessToken.id);
|
expect(response.id).toEqual(ctx.req.accessToken.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throw error', async() => {
|
||||||
|
let error;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await models.VnUser.renewToken({req: {token: null}});
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
const query = 'SELECT * FROM util.debug';
|
||||||
|
|
||||||
|
const debugLog = await models.Application.rawSql(query, null);
|
||||||
|
|
||||||
|
expect(debugLog.length).toEqual(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,6 +64,9 @@
|
||||||
"EmailUser": {
|
"EmailUser": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"Expedition_PrintOut": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"Image": {
|
"Image": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"name": "Expedition_PrintOut",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "dipole.expedition_PrintOut"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"expeditionFk": {
|
||||||
|
"type": "number",
|
||||||
|
"id": true,
|
||||||
|
"description": "id expeditionFk"
|
||||||
|
},
|
||||||
|
"itemFk": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3882,3 +3882,11 @@ INSERT INTO `vn`.`calendarHolidays` (calendarHolidaysTypeFk, dated, calendarHoli
|
||||||
(1, '2001-05-17', 1, 5),
|
(1, '2001-05-17', 1, 5),
|
||||||
(1, '2001-05-18', 1, 5);
|
(1, '2001-05-18', 1, 5);
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO dipole.printer (id, description)
|
||||||
|
VALUES(1, '');
|
||||||
|
|
||||||
|
INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode,
|
||||||
|
truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments)
|
||||||
|
VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL);
|
||||||
|
|
||||||
|
|
|
@ -410,15 +410,26 @@ BEGIN
|
||||||
FROM sage.movConta mc
|
FROM sage.movConta mc
|
||||||
JOIN vn.supplier s ON s.account = mc.CodigoCuenta
|
JOIN vn.supplier s ON s.account = mc.CodigoCuenta
|
||||||
WHERE NOT enlazadoSage
|
WHERE NOT enlazadoSage
|
||||||
)SELECT idClientSupplier, `type`
|
),clientSupplierSync AS(
|
||||||
|
SELECT idClientSupplier, `type`
|
||||||
|
FROM sage.clientSupplier cs
|
||||||
|
WHERE isSync
|
||||||
|
)
|
||||||
|
SELECT idClientSupplier, `type`
|
||||||
FROM sage.clientSupplier cs
|
FROM sage.clientSupplier cs
|
||||||
WHERE NOT isSync
|
WHERE NOT isSync
|
||||||
UNION
|
UNION
|
||||||
SELECT id, 'C'
|
SELECT id, 'C'
|
||||||
FROM client
|
FROM client c
|
||||||
|
LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = c.id
|
||||||
|
AND cs.Type ='C'
|
||||||
|
WHERE cs.idClientSupplier IS NULL
|
||||||
UNION
|
UNION
|
||||||
SELECT id, 'P'
|
SELECT id, 'P'
|
||||||
FROM supplier;
|
FROM supplier s
|
||||||
|
LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = s.id
|
||||||
|
AND cs.Type ='P'
|
||||||
|
WHERE cs.idClientSupplier IS NULL;
|
||||||
|
|
||||||
CALL clientSupplier_add(vCompanyFk);
|
CALL clientSupplier_add(vCompanyFk);
|
||||||
|
|
||||||
|
|
|
@ -12,23 +12,21 @@ BEGIN
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN
|
IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN
|
||||||
|
SELECT util.hasDateOverlapped(
|
||||||
SELECT COUNT(*) > 0 INTO isOverlapping
|
started,
|
||||||
FROM business b
|
ended,
|
||||||
WHERE (util.hasDateOverlapped(
|
NEW.started,
|
||||||
NEW.started,
|
IFNULL(NEW.ended, b.started)
|
||||||
IFNULL(NEW.ended, b.started),
|
) isOverlapped INTO isOverlapping
|
||||||
b.started,
|
FROM vn.business b
|
||||||
IFNULL(b.ended, NEW.started))
|
WHERE workerFk = NEW.workerFK
|
||||||
OR (NEW.ended <=> NULL AND b.ended <=> NULL))
|
AND b.id <> NEW.id
|
||||||
AND b.id <> OLD.id
|
ORDER BY isOverlapped DESC
|
||||||
AND workerFk = OLD.workerFk;
|
LIMIT 1;
|
||||||
|
|
||||||
IF isOverlapping THEN
|
IF isOverlapping THEN
|
||||||
CALL util.throw ('IS_OVERLAPPING');
|
CALL util.throw ('IS_OVERLAPPING');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue