WIP: 7151-dms_refactor_methods #3164

Draft
alexm wants to merge 4 commits from 7151-dms_refactor_methods into dev
6 changed files with 12 additions and 183 deletions
Showing only changes of commit 382309752f - Show all commits

View File

@ -53,34 +53,6 @@ module.exports = Self => {
} }
}); });
Self.uploadFile = async(ctx, id, options) => { Self.uploadFile = async(ctx, id, options) =>
const {Dms, ClaimDms} = Self.app.models; Self.app.models.Dms.uploadFileTemplate(ctx, id, 'ClaimDms', 'claimFk', options);
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;
}
};
}; };

View File

@ -54,36 +54,6 @@ module.exports = Self => {
} }
}); });
Self.uploadFile = async(ctx, id, options) => { Self.uploadFile = async(ctx, id, options) =>
const {Dms, ClientDms} = Self.app.models; Self.app.models.Dms.uploadFileTemplate(ctx, id, 'ClientDms', 'clientFk', options);
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;
}
};
}; };

View File

@ -53,34 +53,6 @@ module.exports = Self => {
} }
}); });
Self.uploadFile = async(ctx, id, options) => { Self.uploadFile = async(ctx, id, options) =>
const {Dms, EntryDms} = Self.app.models; Self.app.models.Dms.uploadFileTemplate(ctx, id, 'EntryDms', 'entryFk', options);
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;
}
};
}; };

View File

@ -53,34 +53,6 @@ module.exports = Self => {
} }
}); });
Self.uploadFile = async(ctx, id, options) => { Self.uploadFile = async(ctx, id, options) =>
const {Dms, SupplierDms} = Self.app.models; Self.app.models.Dms.uploadFileTemplate(ctx, id, 'SupplierDms', 'supplierFk', options);
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;
}
};
}; };

View File

@ -46,35 +46,6 @@ module.exports = Self => {
} }
}); });
Self.uploadFile = async(ctx, id, options) => { Self.uploadFile = async(ctx, id, options) =>
const {Dms, TicketDms} = Self.app.models; Self.app.models.Dms.uploadFileTemplate(ctx, id, 'TicketDms', 'ticketFk', options);
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;
}
};
}; };

View File

@ -46,34 +46,6 @@ module.exports = Self => {
} }
}); });
Self.uploadFile = async(ctx, id) => { Self.uploadFile = async(ctx, id) =>
const {Dms, WorkerDms} = Self.app.models; Self.app.models.Dms.uploadFileTemplate(ctx, id, 'WorkerDms', 'workerFk', options);
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;
}
};
}; };