Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into test
This commit is contained in:
commit
f2ee1df8ac
|
@ -16,29 +16,34 @@ 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;
|
let createTokenOptions = {};
|
||||||
|
let token; let isNotExceeded;
|
||||||
|
try {
|
||||||
|
token = ctx.req.accessToken;
|
||||||
|
|
||||||
const {courtesyTime} = await models.AccessTokenConfig.findOne({
|
const {courtesyTime} = await models.AccessTokenConfig.findOne({
|
||||||
fields: ['courtesyTime']
|
fields: ['courtesyTime']
|
||||||
});
|
});
|
||||||
const isNotExceeded = await Self.validateToken(ctx);
|
isNotExceeded = await Self.validateToken(ctx);
|
||||||
if (isNotExceeded)
|
if (isNotExceeded)
|
||||||
return token;
|
return token;
|
||||||
|
|
||||||
// Schedule to remove current token
|
// Schedule to remove current token
|
||||||
setTimeout(async() => {
|
setTimeout(async() => {
|
||||||
|
let exists;
|
||||||
try {
|
try {
|
||||||
const exists = await models.AccessToken.findById(token.id);
|
exists = await models.AccessToken.findById(token.id);
|
||||||
exists && await Self.logout(token.id);
|
exists && await Self.logout(token.id);
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(err);
|
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);
|
}, courtesyTime * 1000);
|
||||||
|
|
||||||
// Get scopes
|
// Get scopes
|
||||||
|
|
||||||
let createTokenOptions = {};
|
|
||||||
const {scopes} = token;
|
const {scopes} = token;
|
||||||
if (scopes)
|
if (scopes)
|
||||||
createTokenOptions = {scopes: [scopes[0]]};
|
createTokenOptions = {scopes: [scopes[0]]};
|
||||||
|
@ -47,5 +52,15 @@ module.exports = Self => {
|
||||||
const accessToken = await user.accessTokens.create(createTokenOptions);
|
const accessToken = await user.accessTokens.create(createTokenOptions);
|
||||||
|
|
||||||
return {id: accessToken.id, ttl: accessToken.ttl};
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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)
|
||||||
b.started,
|
) isOverlapped INTO isOverlapping
|
||||||
IFNULL(b.ended, NEW.started))
|
FROM vn.business b
|
||||||
OR (NEW.ended <=> NULL AND b.ended <=> NULL))
|
WHERE workerFk = NEW.workerFK
|
||||||
AND b.id <> OLD.id
|
AND b.id <> NEW.id
|
||||||
AND workerFk = OLD.workerFk;
|
ORDER BY isOverlapped DESC
|
||||||
|
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