feat: refs #6897 add cloneEntry and deleteEntry methods with corresponding ACL permissions
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
f8a156b7ab
commit
ef5c2ab3a2
|
@ -1,6 +1,8 @@
|
|||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Entry','getBuyList','READ','ALLOW','ROLE','buyer'),
|
||||
('Entry','create','WRITE','ALLOW','ROLE','buyer'),
|
||||
('Entry','cloneEntry','WRITE','ALLOW','ROLE','buyer'),
|
||||
('Entry','deleteEntry','WRITE','ALLOW','ROLE','buyer'),
|
||||
('EntryType','find','READ','ALLOW','ROLE','buyer'),
|
||||
('EntryConfig','findOne','READ','ALLOW','ROLE','buyer');
|
||||
|
||||
|
|
|
@ -230,6 +230,7 @@ module.exports = Self => {
|
|||
ik.hexJson`;
|
||||
|
||||
const groupByFields = `SUM(b.printedStickers) printedStickers,
|
||||
SUM(b.packing) packing,
|
||||
SUM(b.stickers) stickers,
|
||||
SUM(b.weight) weight,
|
||||
SUM(b.quantity) quantity,
|
||||
|
@ -260,12 +261,12 @@ module.exports = Self => {
|
|||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
let result = await conn.executeStmt(sql, myOptions);
|
||||
|
||||
if (groupBy) {
|
||||
if (groupBy && result.length) {
|
||||
const buys = await Self.app.models.Buy.find({where: {entryFk}}, myOptions);
|
||||
const buysChecked = buys.filter(buy => buy?.isChecked);
|
||||
result[0].isAllChecked = buysChecked.length === buys.length;
|
||||
result[0].isChecked = buysChecked.length === buys.length;
|
||||
}
|
||||
|
||||
console.log('id:', entryFk);
|
||||
return itemsIndex === 0 ? result : result[itemsIndex];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('cloneEntry', {
|
||||
description: 'Clones an entry',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The entry id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/cloneEntry`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.cloneEntry = async(ctx, id, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {userId};
|
||||
let tx;
|
||||
let result;
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
result = await Self.rawSql('CALL entry_clone(?)', [id], myOptions);
|
||||
console.log('result: ', result);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return result[0];
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('deleteEntry', {
|
||||
description: 'Clones an entry',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The entry id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
http: {
|
||||
path: `/:id/deleteEntry`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.deleteEntry = async(ctx, id, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {userId};
|
||||
let tx;
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const entry = await Self.findById(id, null, myOptions);
|
||||
console.log('entry: ', entry);
|
||||
await entry.updateAttribute('travelFk', null, myOptions);
|
||||
await Self.rawSql('DELETE FROM vn.duaEntry WHERE entryFk = ?;', [id], myOptions);
|
||||
await Self.rawSql(`
|
||||
DELETE i.*
|
||||
FROM vn.invoiceIn i
|
||||
JOIN vn.entry e ON e.invoiceInFk = i.id
|
||||
WHERE e.id = ?`, [id], myOptions
|
||||
);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -238,7 +238,6 @@ module.exports = Self => {
|
|||
return {[`et.code`]: value};
|
||||
}
|
||||
});
|
||||
console.log('where: ', where);
|
||||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const client = await Self.app.models.Client.findById(userId, myOptions);
|
||||
|
@ -290,11 +289,11 @@ module.exports = Self => {
|
|||
t.isReceived
|
||||
FROM vn.entry e
|
||||
JOIN vn.supplier s ON s.id = e.supplierFk
|
||||
JOIN vn.travel t ON t.id = e.travelFk
|
||||
JOIN vn.warehouse w ON w.id = t.warehouseInFk
|
||||
JOIN vn.warehouse w2 ON w2.id = t.warehouseOutFk
|
||||
JOIN vn.company co ON co.id = e.companyFk
|
||||
JOIN vn.currency cu ON cu.id = e.currencyFk
|
||||
LEFT JOIN vn.travel t ON t.id = e.travelFk
|
||||
LEFT JOIN vn.warehouse w ON w.id = t.warehouseInFk
|
||||
LEFT JOIN vn.warehouse w2 ON w2.id = t.warehouseOutFk
|
||||
LEFT JOIN vn.company co ON co.id = e.companyFk
|
||||
LEFT JOIN vn.currency cu ON cu.id = e.currencyFk
|
||||
LEFT JOIN vn.awb a ON a.id = t.awbFk
|
||||
LEFT JOIN vn.agencyMode am ON am.id = t.agencyModeFk
|
||||
LEFT JOIN vn.entryType et ON et.code = e.typeFk`
|
||||
|
|
|
@ -16,6 +16,8 @@ module.exports = Self => {
|
|||
require('../methods/entry/buyLabelSupplier')(Self);
|
||||
require('../methods/entry-buys/getBuyList')(Self);
|
||||
require('../methods/entry-buys/getBuyUltimate')(Self);
|
||||
require('../methods/entry/cloneEntry')(Self);
|
||||
require('../methods/entry/deleteEntry')(Self);
|
||||
|
||||
Self.observe('before save', async(ctx, options) => {
|
||||
if (ctx.isNewInstance) return;
|
||||
|
|
|
@ -56,8 +56,7 @@
|
|||
"required": true
|
||||
},
|
||||
"travelFk": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
"type": "number"
|
||||
},
|
||||
"companyFk": {
|
||||
"type": "number",
|
||||
|
@ -101,6 +100,11 @@
|
|||
"type": "belongsTo",
|
||||
"model": "EntryType",
|
||||
"foreignKey": "typeFk"
|
||||
},
|
||||
"invoiceIn": {
|
||||
"type": "belongsTo",
|
||||
"model": "InvoiceIn",
|
||||
"foreignKey": "invoiceInFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue