#2051 - DMS unify methods #1888
|
@ -22,8 +22,8 @@ module.exports = Self => {
|
|||
|
||||
Self.removeFile = async(ctx, id, options) => {
|
||||
const models = Self.app.models;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('removeFile', {
|
||||
description: 'Removes a claim document',
|
||||
|
@ -19,8 +21,8 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.removeFile = async(ctx, id, options) => {
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -31,19 +33,18 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
// const {models: ClaimDms, Dms} = Self.app.models;
|
||||
// const targetClaimDms = await ClaimDms.findById(id, null, myOptions);
|
||||
// await Dms.findById(targetClaimDms.dmsFk, null, myOptions);
|
||||
// const trashDmsType = await DmsType.findOne({where: {code: 'trash'}}, myOptions);
|
||||
myOptions.model = 'ClaimDms';
|
||||
const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions);
|
||||
// await targetClaimDms.destroy(myOptions);
|
||||
const claimDms = await Self.findById(id, null, myOptions);
|
||||
|
||||
// await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
||||
const targetDms = await Self.app.models.Dms.removeFile(ctx, claimDms.dmsFk, myOptions);
|
||||
|
||||
if (!targetDms || ! claimDms)
|
||||
throw new UserError('Try again');
|
||||
|
||||
jsegarra marked this conversation as resolved
|
||||
const claimDestroyed = await claimDms.destroy(myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return targetDms;
|
||||
return claimDestroyed;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -19,9 +19,8 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.removeFile = async(ctx, id, options) => {
|
||||
const models = Self.app.models;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -34,13 +33,16 @@ module.exports = Self => {
|
|||
try {
|
||||
const clientDms = await Self.findById(id, null, myOptions);
|
||||
|
||||
await models.Dms.removeFile(ctx, clientDms.dmsFk, myOptions);
|
||||
const targetDms = await Self.app.models.Dms.removeFile(ctx, clientDms.dmsFk, myOptions);
|
||||
|
||||
const destroyedClient = await clientDms.destroy(myOptions);
|
||||
if (!targetDms || !clientDms)
|
||||
throw new UserError('Try again');
|
||||
|
||||
const clientDestroyed = await clientDms.destroy(myOptions);
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
ya que cambiamos el nombre de la variable, para mi queda mas claro, ya que cambiamos el nombre de la variable, para mi queda mas claro,
clientDmsDestroyed porque en realidad no se elimina un cliente sino la relacion entre cliente y dms
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return destroyedClient;
|
||||
return clientDestroyed;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -31,19 +31,18 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
// const targetTicketDms = await models.TicketDms.findById(id, null, myOptions);
|
||||
myOptions.model = 'TicketDms';
|
||||
// await models.Dms.findById(targetTicketDms.dmsFk, null, myOptions);
|
||||
// const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions);
|
||||
const ticketDms = await Self.findById(id, null, myOptions);
|
||||
|
||||
const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions);
|
||||
// await targetTicketDms.destroy(myOptions);
|
||||
const targetDms = await Self.app.models.Dms.removeFile(ctx, ticketDms.dmsFk, myOptions);
|
||||
|
||||
// await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
||||
if (!targetDms || !ticketDms)
|
||||
throw new UserError('Try again');
|
||||
|
||||
const ticketDestroyed = await ticketDms.destroy(myOptions);
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
ticketDmsDestroyed o si lo quieres generico selfDestroyed... ticketDmsDestroyed o si lo quieres generico selfDestroyed...
jsegarra
commented
He usado la misma sintaxis para todo %modelo%DmsDestroyed He usado la misma sintaxis para todo %modelo%DmsDestroyed
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return targetDms;
|
||||
return ticketDestroyed;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -19,25 +19,28 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.removeFile = async(ctx, id, options) => {
|
||||
jgallego
commented
renombrar id por dmsFk renombrar id por dmsFk
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const myOptions = {};
|
||||
const WorkerDms = await Self.findById(id, null, myOptions);
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
const targetDms = await Self.app.models.Dms.removeFile(ctx, WorkerDms.dmsFk, myOptions);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
// const workerDms = await Self.findById(id);
|
||||
myOptions.model = 'WorkerDms';
|
||||
await models.Dms.removeFile(ctx, id, myOptions);
|
||||
// await workerDms.destroy();
|
||||
if (!targetDms || !WorkerDms)
|
||||
throw new UserError('Try again');
|
||||
|
||||
const workerDestroyed = await WorkerDms.destroy(myOptions);
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return workerDms;
|
||||
return workerDestroyed;
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
|
|
Loading…
Reference in New Issue
dejar aquí lo que aplica al modelo claim-dms y lo otro moverlo a dms