2021-09-24 06:24:34 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('toBook', {
|
|
|
|
description: 'To book the invoiceIn',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: {
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
description: 'The invoiceIn id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
},
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: '/:id/toBook',
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.toBook = async(ctx, id, options) => {
|
|
|
|
let tx;
|
2023-06-01 06:32:06 +00:00
|
|
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
2021-09-24 06:24:34 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-06-08 12:42:07 +00:00
|
|
|
await Self.rawSql(`CALL vn.invoiceIn_booking(?)`, [id], myOptions);
|
2021-09-24 06:24:34 +00:00
|
|
|
if (tx) await tx.commit();
|
|
|
|
} catch (e) {
|
|
|
|
if (tx) await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|