mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-18 05:22:48 +01:00
* feat: new routes for flags API + flag get + flag creation, migration from socket method + flag update, migration from socket method * fixed bug where you could not unassign someone from a flag * feat: tests for new flags API added missing files for schema update * fix: flag tests to use Write API instead of sockets * feat: flag notes API + tests * chore: remove debug line * test: fix breaking test on mongo
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const user = require('../../user');
|
|
const flags = require('../../flags');
|
|
const api = require('../../api');
|
|
const helpers = require('../helpers');
|
|
|
|
const Flags = module.exports;
|
|
|
|
Flags.create = async (req, res) => {
|
|
const flagObj = await api.flags.create(req, { ...req.body });
|
|
helpers.formatApiResponse(200, res, await user.isPrivileged(req.uid) ? flagObj : undefined);
|
|
};
|
|
|
|
Flags.get = async (req, res) => {
|
|
const isPrivileged = await user.isPrivileged(req.uid);
|
|
if (!isPrivileged) {
|
|
return helpers.formatApiResponse(403, res);
|
|
}
|
|
|
|
helpers.formatApiResponse(200, res, await flags.get(req.params.flagId));
|
|
};
|
|
|
|
Flags.update = async (req, res) => {
|
|
const history = await api.flags.update(req, {
|
|
flagId: req.params.flagId,
|
|
...req.body,
|
|
});
|
|
|
|
helpers.formatApiResponse(200, res, { history });
|
|
};
|
|
|
|
Flags.appendNote = async (req, res) => {
|
|
const payload = await api.flags.appendNote(req, {
|
|
flagId: req.params.flagId,
|
|
...req.body,
|
|
});
|
|
|
|
helpers.formatApiResponse(200, res, payload);
|
|
};
|
|
|
|
Flags.deleteNote = async (req, res) => {
|
|
const payload = await api.flags.deleteNote(req, {
|
|
...req.params,
|
|
});
|
|
|
|
helpers.formatApiResponse(200, res, payload);
|
|
};
|