added endpoint for group ownership transfer
This commit is contained in:
parent
947dc720a5
commit
63aaa30d92
|
@ -16,6 +16,7 @@
|
|||
"group not an owner": "You are not an owner of this group!",
|
||||
"group not a member": "You are not a member of this group!",
|
||||
"name not specified": "New name of a group is not specified!",
|
||||
"new owner not specified": "ID of a new group owner is not specified!",
|
||||
"abstract product not found": "Such abstract product is not found!",
|
||||
"abstract product invalid syntax": "Invalid syntax in one of user's parameters!",
|
||||
"barcode not found": "Such barcode not found!",
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"group not an owner": "Вы не владелец этой группы!",
|
||||
"group not a member": "Вы не участник этой группы!",
|
||||
"name not specified": "Не указано новое имя группы!",
|
||||
"new owner not specified": "Не указан ID нового владельца группы!",
|
||||
"abstract product not found": "Такой абстрактный продукт не найден!",
|
||||
"abstract product invalid syntax": "Неправильный синткасис в одном из параметров абстрактного продукта!",
|
||||
"barcode not found": "Такой штрихкод не найден!",
|
||||
|
|
|
@ -87,6 +87,17 @@ class GroupController {
|
|||
|
||||
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
|
||||
}
|
||||
|
||||
async transferOwnership(req, res) {
|
||||
const groupId = req.params.groupId;
|
||||
const userId = req.body.userId;
|
||||
|
||||
if (!userId) throw new customError(`New owner id is not specified`, responseCodes.responses.groups.new_owner_not_specified);
|
||||
|
||||
await GroupService.transferOwnership(groupId, userId);
|
||||
|
||||
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
|
||||
}
|
||||
}
|
||||
|
||||
export default new GroupController();
|
||||
|
|
|
@ -24,7 +24,8 @@ const responses = {
|
|||
id_not_found: "group id not found",
|
||||
not_an_owner: "group not an owner",
|
||||
not_a_member: "group not a member",
|
||||
name_not_specified: "name not specified"
|
||||
name_not_specified: "name not specified",
|
||||
new_owner_not_specified: "new owner not specified"
|
||||
},
|
||||
abstractproducts: {
|
||||
not_found: "abstract product not found",
|
||||
|
@ -144,6 +145,8 @@ const getHTTPCode = (type) => {
|
|||
return 403
|
||||
case responses.groups.name_not_specified:
|
||||
return 400
|
||||
case responses.new_owner_not_specified:
|
||||
return 400
|
||||
|
||||
case responses.abstractproducts.not_found:
|
||||
return 404
|
||||
|
|
|
@ -9,10 +9,10 @@ const GroupRouter = new Router();
|
|||
GroupRouter.post('/create/:groupName', tryHandler(auth.authenticate), tryHandler(GroupController.create));
|
||||
GroupRouter.post('/join/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.requirePassword), tryHandler(auth.checkGroupPassword), tryHandler(GroupController.join));
|
||||
GroupRouter.post('/password/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.authorizeGroupOwner), tryHandler(auth.requirePassword), tryHandler(GroupController.updatePassword));
|
||||
GroupRouter.get('/byName/:groupName', tryHandler(auth.authenticate), tryHandler(existance.groupNameExists), tryHandler(GroupController.getByName))
|
||||
GroupRouter.get('/byId/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getById))
|
||||
GroupRouter.get('/getUsers/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getUsersInGroup))
|
||||
GroupRouter.get('/adminId/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getAdminId))
|
||||
GroupRouter.get('/byName/:groupName', tryHandler(auth.authenticate), tryHandler(existance.groupNameExists), tryHandler(GroupController.getByName));
|
||||
GroupRouter.get('/byId/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getById));
|
||||
GroupRouter.get('/getUsers/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getUsersInGroup));
|
||||
GroupRouter.get('/adminId/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getAdminId));
|
||||
GroupRouter.post('/rename/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.authorizeGroupOwner), tryHandler(GroupController.rename));
|
||||
|
||||
GroupRouter.post('/transferOwnership/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.authorizeGroupOwner), tryHandler(GroupController.transferOwnership));
|
||||
export default GroupRouter;
|
|
@ -41,6 +41,10 @@ class GroupService {
|
|||
async rename(groupId, newName) {
|
||||
await db.query("UPDATE groups SET name = $1 WHERE id = $2", [newName, groupId]).catch((e) => errorHandler(e, "groups"));;
|
||||
}
|
||||
|
||||
async transferOwnership(groupId, userId) {
|
||||
await db.query("UPDATE groups SET admin_id = $1 WHERE id = $2", [userId, groupId])
|
||||
}
|
||||
};
|
||||
|
||||
export default new GroupService();
|
Loading…
Reference in New Issue