minor refactor
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2021-01-22 14:30:46 +01:00
parent aab9797d3f
commit 7bdfb36f25
3 changed files with 20 additions and 20 deletions

View File

@ -1,3 +1,3 @@
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES ('printServerQueue', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'); VALUES ('PrintServerQueue', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee');
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('FixedPrice', '*', '*', 'ALLOW', 'ROLE', 'buyer'); INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('FixedPrice', '*', '*', 'ALLOW', 'ROLE', 'buyer');

View File

@ -25,36 +25,36 @@ module.exports = function(Self) {
}); });
Self.makeInvoice = async(ctx, id) => { Self.makeInvoice = async(ctx, id) => {
let userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
let models = Self.app.models; const models = Self.app.models;
let tx = await Self.beginTransaction({}); const tx = await Self.beginTransaction({});
try { try {
let options = {transaction: tx}; const options = {transaction: tx};
let filter = {fields: ['id', 'clientFk', 'companyFk']}; const filter = {fields: ['id', 'clientFk', 'companyFk']};
let ticket = await models.Ticket.findById(id, filter, options); const ticket = await models.Ticket.findById(id, filter, options);
let clientCanBeInvoiced = await models.Client.canBeInvoiced(ticket.clientFk); const clientCanBeInvoiced = await models.Client.canBeInvoiced(ticket.clientFk);
if (!clientCanBeInvoiced) if (!clientCanBeInvoiced)
throw new UserError(`This client can't be invoiced`); throw new UserError(`This client can't be invoiced`);
let ticketCanBeInvoiced = await models.Ticket.canBeInvoiced(ticket.id); const ticketCanBeInvoiced = await models.Ticket.canBeInvoiced(ticket.id);
if (!ticketCanBeInvoiced) if (!ticketCanBeInvoiced)
throw new UserError(`This ticket can't be invoiced`); throw new UserError(`This ticket can't be invoiced`);
let query = `SELECT vn.invoiceSerial(?, ?, ?) AS serial`; const query = `SELECT vn.invoiceSerial(?, ?, ?) AS serial`;
let [result] = await Self.rawSql(query, [ticket.clientFk, ticket.companyFk, 'R'], options); const [result] = await Self.rawSql(query, [ticket.clientFk, ticket.companyFk, 'R'], options);
let serial = result.serial; const serial = result.serial;
await Self.rawSql('CALL invoiceFromTicket(?)', [id], options); await Self.rawSql('CALL invoiceFromTicket(?)', [id], options);
await Self.rawSql('CALL invoiceOut_new(?, CURDATE(), null, @invoiceId)', [serial], options); await Self.rawSql('CALL invoiceOut_new(?, CURDATE(), null, @invoiceId)', [serial], options);
let [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], options); const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], options);
let invoiceId = resultInvoice.id; const invoiceId = resultInvoice.id;
let ticketInvoice = await models.Ticket.findById(id, {fields: ['refFk']}, options); const ticketInvoice = await models.Ticket.findById(id, {fields: ['refFk']}, options);
await models.TicketLog.create({ await models.TicketLog.create({
originFk: ticket.id, originFk: ticket.id,

View File

@ -9,22 +9,22 @@
}, },
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "number",
"id": true, "id": true,
"description": "Identifier" "description": "Identifier"
}, },
"priorityFk": { "priorityFk": {
"type": "Number" "type": "number"
}, },
"reportFk": { "reportFk": {
"type": "Number", "type": "number",
"required": true "required": true
}, },
"param1": { "param1": {
"type": "Number" "type": "number"
}, },
"workerFk": { "workerFk": {
"type": "Number", "type": "number",
"required": true "required": true
} }
} }