WIP: 7151-dms_refactor_methods #3164
|
@ -53,34 +53,6 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.uploadFile = async(ctx, id, options) => {
|
||||
const {Dms, ClaimDms} = 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 uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||
|
||||
const promises = uploadedFiles.map(dms => ClaimDms.create({
|
||||
claimFk: id,
|
||||
dmsFk: dms.id
|
||||
}, myOptions));
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return uploadedFiles;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
Self.uploadFile = async(ctx, id, options) =>
|
||||
Self.app.models.Dms.uploadFileTemplate(ctx, id, 'ClaimDms', 'claimFk', options);
|
||||
};
|
||||
|
|
|
@ -54,36 +54,6 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.uploadFile = async(ctx, id, options) => {
|
||||
const {Dms, ClientDms} = 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 uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||
const promises = uploadedFiles.map(dms =>
|
||||
ClientDms.create({
|
||||
clientFk: id,
|
||||
dmsFk: dms.id
|
||||
}, myOptions)
|
||||
|
||||
);
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return uploadedFiles;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
Self.uploadFile = async(ctx, id, options) =>
|
||||
Self.app.models.Dms.uploadFileTemplate(ctx, id, 'ClientDms', 'clientFk', options);
|
||||
};
|
||||
|
|
|
@ -53,34 +53,6 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.uploadFile = async(ctx, id, options) => {
|
||||
const {Dms, EntryDms} = 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 uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||
|
||||
const promises = uploadedFiles.map(dms => EntryDms.create({
|
||||
entryFk: id,
|
||||
dmsFk: dms.id
|
||||
}, myOptions));
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return uploadedFiles;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
Self.uploadFile = async(ctx, id, options) =>
|
||||
Self.app.models.Dms.uploadFileTemplate(ctx, id, 'EntryDms', 'entryFk', options);
|
||||
};
|
||||
|
|
|
@ -53,34 +53,6 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.uploadFile = async(ctx, id, options) => {
|
||||
const {Dms, SupplierDms} = 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 uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||
|
||||
const promises = uploadedFiles.map(dms => SupplierDms.create({
|
||||
supplierFk: id,
|
||||
dmsFk: dms.id
|
||||
}, myOptions));
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return uploadedFiles;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
Self.uploadFile = async(ctx, id, options) =>
|
||||
Self.app.models.Dms.uploadFileTemplate(ctx, id, 'SupplierDms', 'supplierFk', options);
|
||||
};
|
||||
|
|
|
@ -46,35 +46,6 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.uploadFile = async(ctx, id, options) => {
|
||||
const {Dms, TicketDms} = 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 uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||
|
||||
const promises = uploadedFiles.map(dms => TicketDms.create({
|
||||
ticketFk: id,
|
||||
dmsFk: dms.id
|
||||
}, myOptions));
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return uploadedFiles;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
Self.uploadFile = async(ctx, id, options) =>
|
||||
Self.app.models.Dms.uploadFileTemplate(ctx, id, 'TicketDms', 'ticketFk', options);
|
||||
};
|
||||
|
|
|
@ -46,34 +46,6 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.uploadFile = async(ctx, id) => {
|
||||
const {Dms, WorkerDms} = 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 uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||
const promises = uploadedFiles.map(dms =>
|
||||
WorkerDms.create({
|
||||
workerFk: id,
|
||||
dmsFk: dms.id
|
||||
}, myOptions));
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return uploadedFiles;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
Self.uploadFile = async(ctx, id) =>
|
||||
Self.app.models.Dms.uploadFileTemplate(ctx, id, 'WorkerDms', 'workerFk', options);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue