added logs
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
b446f5cf5f
commit
ef6b06e147
|
@ -40,6 +40,7 @@ module.exports = Self => {
|
|||
const TempContainer = models.TempContainer;
|
||||
const fileOptions = {};
|
||||
const args = ctx.args;
|
||||
const user = ctx.req.accessToken.userId;
|
||||
|
||||
let srcFile;
|
||||
try {
|
||||
|
@ -59,7 +60,7 @@ module.exports = Self => {
|
|||
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
||||
srcFile = path.join(file.client.root, file.container, file.name);
|
||||
|
||||
await models.Image.registerImage(args.collection, srcFile, args.fileName, args.id);
|
||||
await models.Image.registerImage(args.collection, srcFile, args.fileName, args.id, user);
|
||||
} catch (e) {
|
||||
if (fs.existsSync(srcFile))
|
||||
await fs.unlink(srcFile);
|
||||
|
|
|
@ -46,7 +46,7 @@ module.exports = Self => {
|
|||
}).bitmap;
|
||||
}
|
||||
|
||||
Self.registerImage = async(collectionName, srcFilePath, fileName, entityId) => {
|
||||
Self.registerImage = async(collectionName, srcFilePath, fileName, entityId, user) => {
|
||||
const models = Self.app.models;
|
||||
const tx = await Self.beginTransaction({});
|
||||
const myOptions = {transaction: tx};
|
||||
|
@ -140,6 +140,7 @@ module.exports = Self => {
|
|||
|
||||
const item = await model.findById(entityId, null, myOptions);
|
||||
if (item) {
|
||||
collection.model == 'item' ? fileName = fileName + '-' + user : fileName;
|
||||
await item.updateAttribute(
|
||||
collection.property,
|
||||
fileName,
|
||||
|
|
|
@ -21,14 +21,34 @@ module.exports = Self => {
|
|||
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
let currentInstance = ctx.currentInstance;
|
||||
let instance = ctx.currentInstance;
|
||||
let oldInstance;
|
||||
let newInstance;
|
||||
ctx.hookState.oldInstance === undefined ? oldInstance = false : oldInstance = ctx.hookState.oldInstance;
|
||||
ctx.hookState.newInstance === undefined ? newInstance = false : newInstance = ctx.hookState.newInstance;
|
||||
if (oldInstance.image && newInstance.image) {
|
||||
let query = `UPDATE vn.item SET doPhoto = 0 WHERE id = ${currentInstance.id}`;
|
||||
let image = newInstance.image.split('-')[0];
|
||||
let user = newInstance.image.split('-')[1];
|
||||
|
||||
ctx.hookState.newInstance.image = image;
|
||||
|
||||
let query = `UPDATE vn.item SET doPhoto=0 WHERE id = ${instance.id}`;
|
||||
await Self.rawSql(query);
|
||||
let logQuery =
|
||||
'INSERT INTO vn.itemLog(originFk, userFk, action, creationDate, description, oldInstance, newInstance) ' +
|
||||
'VALUES (?, ?, ?, ?, ?, ?, ?)';
|
||||
|
||||
let logParams = [
|
||||
instance.id,
|
||||
user,
|
||||
'update',
|
||||
new Date(),
|
||||
'Image',
|
||||
JSON.stringify(oldInstance),
|
||||
JSON.stringify(newInstance)
|
||||
];
|
||||
|
||||
await Self.rawSql(logQuery, logParams);
|
||||
}
|
||||
await Self.availableId(ctx);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue