refs #6274 fix locale
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-01-03 10:13:56 +01:00
parent b086da1936
commit 5dc49d226a
4 changed files with 28 additions and 13 deletions

View File

@ -200,5 +200,6 @@
"Try again": "Try again", "Try again": "Try again",
"keepPrice": "keepPrice", "keepPrice": "keepPrice",
"Cannot past travels with entries": "Cannot past travels with entries", "Cannot past travels with entries": "Cannot past travels with entries",
"It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}" "It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}",
"Incorrect pin": "Incorrect pin."
} }

View File

@ -331,8 +331,7 @@
"Cannot past travels with entries": "No se pueden pasar envíos con entradas", "Cannot past travels with entries": "No se pueden pasar envíos con entradas",
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}", "It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}",
"This user does not have an assigned tablet": "Este usuario no tiene tablet asignada", "This user does not have an assigned tablet": "Este usuario no tiene tablet asignada",
"Incorrect pin.": "Pin incorrecto.", "Incorrect pin": "Pin incorrecto.",
"You already have the mailAlias": "Ya tienes este alias de correo", "You already have the mailAlias": "Ya tienes este alias de correo",
"The alias cant be modified": "Este alias de correo no puede ser modificado" "The alias cant be modified": "Este alias de correo no puede ser modificado"
} }

View File

@ -1,7 +1,7 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('login', { Self.remoteMethodCtx('login', {
description: 'Consult the user\'s information and the buttons that must be activated after logging in', description: 'Consult the user\'s information and the buttons that must be activated after logging in',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
@ -21,14 +21,15 @@ module.exports = Self => {
} }
}); });
Self.login = async(pin, options) => { Self.login = async(ctx, pin, options) => {
const myOptions = {}; const myOptions = {};
const $t = ctx.req.__;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const query = `CALL vn.workerTimeControl_login(?)`; const query = `CALL vn.workerTimeControl_login(?)`;
const [[user]] = await Self.rawSql(query, [pin], myOptions); const [[user]] = await Self.rawSql(query, [pin], myOptions);
if (!user) throw new UserError('Incorrect pin.'); if (!user) throw new UserError($t('Incorrect pin'));
return user; return user;
}; };
}; };

View File

@ -1,20 +1,34 @@
const UserError = require('vn-loopback/util/user-error');
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
const UserError = require('vn-loopback/util/user-error');
describe('workerTimeControl login()', () => { describe('workerTimeControl login()', () => {
let ctx;
beforeAll(async() => {
ctx = {
accessToken: {userId: 9},
req: {
headers: {origin: 'http://localhost'},
__: key => key
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx
});
});
it('should correctly login', async() => { it('should correctly login', async() => {
const response = await models.WorkerTimeControl.login(9); const response = await models.WorkerTimeControl.login(ctx, 9);
expect(response.name).toBe('developer'); expect(response.name).toBe('developer');
}); });
it('should throw UserError if pin is not provided', async() => { it('should throw UserError if pin is not provided', async() => {
try { try {
await models.WorkerTimeControl.login(); await models.WorkerTimeControl.login(ctx);
} catch (error) { } catch (error) {
expect(error).toBeInstanceOf(UserError); expect(error).toBeInstanceOf(UserError);
expect(error.message).toBe('Incorrect pin.'); expect(error.message).toBe('Incorrect pin');
} }
}); });
}); });