fix: return the edited/changed/delete entity from API
This commit is contained in:
parent
9de50b26f1
commit
fe314a742f
|
@ -1,6 +1,6 @@
|
|||
const Route = require('../../structures/Route');
|
||||
|
||||
class tagAddPOST extends Route {
|
||||
class tagAddBatchPOST extends Route {
|
||||
constructor() {
|
||||
super('/file/tag/addBatch', 'post');
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ class tagAddPOST extends Route {
|
|||
|
||||
return res.json({
|
||||
message: 'Successfully added tags to file',
|
||||
data: addedTags,
|
||||
data: { fileId, tags: addedTags },
|
||||
errors,
|
||||
});
|
||||
// eslint-disable-next-line consistent-return
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = tagAddPOST;
|
||||
module.exports = tagAddBatchPOST;
|
||||
|
|
|
@ -27,7 +27,7 @@ class tagAddPOST extends Route {
|
|||
|
||||
return res.json({
|
||||
message: 'Successfully added tag to file',
|
||||
data: tagName,
|
||||
data: { fileId, tag },
|
||||
});
|
||||
// eslint-disable-next-line consistent-return
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class tagDELETE extends Route {
|
|||
Delete the tag
|
||||
*/
|
||||
await db.table('tags').where({ id }).delete();
|
||||
return res.json({ message: 'The tag was deleted successfully' });
|
||||
return res.json({ message: 'The tag was deleted successfully', data: tag });
|
||||
} catch (error) {
|
||||
return super.error(res, error);
|
||||
}
|
||||
|
|
|
@ -18,14 +18,18 @@ class tagPOST extends Route {
|
|||
if (tag) return res.status(401).json({ message: 'There\'s already a tag with that name' });
|
||||
|
||||
const now = moment.utc().toDate();
|
||||
await db.table('tags').insert({
|
||||
const insertObj = {
|
||||
name,
|
||||
userId: user.id,
|
||||
createdAt: now,
|
||||
editedAt: now,
|
||||
});
|
||||
};
|
||||
|
||||
return res.json({ message: 'The tag was created successfully' });
|
||||
const dbRes = await db.table('tags').insert(insertObj);
|
||||
|
||||
insertObj.id = dbRes.pop();
|
||||
|
||||
return res.json({ message: 'The tag was created successfully', data: insertObj });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,27 +3,27 @@ const { dump } = require('dumper.js');
|
|||
|
||||
class Log {
|
||||
static info(args) {
|
||||
if (this.checkIfArrayOrObject(args)) dump(args);
|
||||
if (Log.checkIfArrayOrObject(args)) dump(args);
|
||||
else console.log(args); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
static success(args) {
|
||||
if (this.checkIfArrayOrObject(args)) dump(args);
|
||||
if (Log.checkIfArrayOrObject(args)) dump(args);
|
||||
else console.log(chalk.green(args)); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
static warn(args) {
|
||||
if (this.checkIfArrayOrObject(args)) dump(args);
|
||||
if (Log.checkIfArrayOrObject(args)) dump(args);
|
||||
else console.log(chalk.yellow(args)); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
static error(args) {
|
||||
if (this.checkIfArrayOrObject(args)) dump(args);
|
||||
if (Log.checkIfArrayOrObject(args)) dump(args);
|
||||
else console.log(chalk.red(args)); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
static debug(args) {
|
||||
if (this.checkIfArrayOrObject(args)) dump(args);
|
||||
if (Log.checkIfArrayOrObject(args)) dump(args);
|
||||
else console.log(chalk.gray(args)); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue