invite management
This commit is contained in:
parent
d1cf9f4c66
commit
c66c847ec1
6 changed files with 87 additions and 20 deletions
|
@ -37,7 +37,7 @@ export default abstract class InviteCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete invite by mail and token
|
* @description delete invite by mail and token
|
||||||
* @param DeleteRefreshCommand
|
* @param DeleteInviteCommand
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async deleteByTokenAndMail(deleteInvite: DeleteInviteCommand): Promise<any> {
|
static async deleteByTokenAndMail(deleteInvite: DeleteInviteCommand): Promise<any> {
|
||||||
|
@ -53,4 +53,22 @@ export default abstract class InviteCommandHandler {
|
||||||
throw new InternalException("failed invite removal", err);
|
throw new InternalException("failed invite removal", err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description delete invite by mail
|
||||||
|
* @param DeleteByMailInviteCommand
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
|
static async deleteByMail(mail: string): Promise<any> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(invite)
|
||||||
|
.where("invite.mail = :mail", { mail })
|
||||||
|
.execute()
|
||||||
|
.then((res) => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("failed invite removal", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import CustomRequestException from "../exceptions/customRequestException";
|
||||||
import { CLUB_NAME } from "../env.defaults";
|
import { CLUB_NAME } from "../env.defaults";
|
||||||
import { CreateUserPermissionCommand } from "../command/userPermissionCommand";
|
import { CreateUserPermissionCommand } from "../command/userPermissionCommand";
|
||||||
import UserPermissionCommandHandler from "../command/userPermissionCommandHandler";
|
import UserPermissionCommandHandler from "../command/userPermissionCommandHandler";
|
||||||
|
import InviteFactory from "../factory/admin/invite";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all invites
|
* @description get all invites
|
||||||
|
@ -25,7 +26,11 @@ import UserPermissionCommandHandler from "../command/userPermissionCommandHandle
|
||||||
* @param res {Response} Express res object
|
* @param res {Response} Express res object
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export async function getInvites(req: Request, res: Response): Promise<any> {}
|
export async function getInvites(req: Request, res: Response): Promise<any> {
|
||||||
|
let invites = await InviteService.getAll();
|
||||||
|
|
||||||
|
res.json(InviteFactory.mapToBase(invites));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description start first user
|
* @description start first user
|
||||||
|
@ -157,11 +162,15 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete invites
|
* @description delete invite by mail
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
* @param res {Response} Express res object
|
* @param res {Response} Express res object
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export async function deleteInvites(req: Request, res: Response): Promise<any> {
|
export async function deleteInvite(req: Request, res: Response): Promise<any> {
|
||||||
const id = parseInt(req.params.id);
|
const mail = req.params.mail;
|
||||||
|
|
||||||
|
await InviteCommandHandler.deleteByMail(mail);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
|
27
src/factory/admin/invite.ts
Normal file
27
src/factory/admin/invite.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { invite } from "../../entity/invite";
|
||||||
|
import { InviteViewModel } from "../../viewmodel/admin/invite.models";
|
||||||
|
|
||||||
|
export default abstract class InviteFactory {
|
||||||
|
/**
|
||||||
|
* @description map record to invite
|
||||||
|
* @param {invite} record
|
||||||
|
* @returns {InviteViewModel}
|
||||||
|
*/
|
||||||
|
public static mapToSingle(record: invite): InviteViewModel {
|
||||||
|
return {
|
||||||
|
mail: record.mail,
|
||||||
|
username: record.username,
|
||||||
|
firstname: record.firstname,
|
||||||
|
lastname: record.lastname,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description map records to invite
|
||||||
|
* @param {Array<invite>} records
|
||||||
|
* @returns {Array<InviteViewModel>}
|
||||||
|
*/
|
||||||
|
public static mapToBase(records: Array<invite>): Array<InviteViewModel> {
|
||||||
|
return records.map((r) => this.mapToSingle(r));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +1,15 @@
|
||||||
import express, { Request, Response } from "express";
|
import express, { Request, Response } from "express";
|
||||||
import PermissionHelper from "../../helpers/permissionHelper";
|
import PermissionHelper from "../../helpers/permissionHelper";
|
||||||
import {
|
import { deleteInvite, getInvites, inviteUser } from "../../controller/inviteController";
|
||||||
deleteUser,
|
|
||||||
getAllUsers,
|
|
||||||
getUserById,
|
|
||||||
getUserPermissions,
|
|
||||||
getUserRoles,
|
|
||||||
updateUser,
|
|
||||||
updateUserPermissions,
|
|
||||||
updateUserRoles,
|
|
||||||
} from "../../controller/admin/userController";
|
|
||||||
import { inviteUser } from "../../controller/inviteController";
|
|
||||||
|
|
||||||
var router = express.Router({ mergeParams: true });
|
var router = express.Router({ mergeParams: true });
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
await getAllUsers(req, res);
|
await getInvites(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/invite",
|
"/",
|
||||||
PermissionHelper.passCheckMiddleware("create", "user", "user"),
|
PermissionHelper.passCheckMiddleware("create", "user", "user"),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
await inviteUser(req, res);
|
await inviteUser(req, res);
|
||||||
|
@ -27,10 +17,10 @@ router.post(
|
||||||
);
|
);
|
||||||
|
|
||||||
router.delete(
|
router.delete(
|
||||||
"/:id",
|
"/:mail",
|
||||||
PermissionHelper.passCheckMiddleware("delete", "user", "user"),
|
PermissionHelper.passCheckMiddleware("delete", "user", "user"),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
//await deleteUser(req, res);
|
await deleteInvite(req, res);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,23 @@ import { invite } from "../entity/invite";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
|
|
||||||
export default abstract class InviteService {
|
export default abstract class InviteService {
|
||||||
|
/**
|
||||||
|
* @description get all invites
|
||||||
|
* @returns {Promise<Array<invite>>}
|
||||||
|
*/
|
||||||
|
static async getAll(): Promise<Array<invite>> {
|
||||||
|
return await dataSource
|
||||||
|
.getRepository(invite)
|
||||||
|
.createQueryBuilder("invite")
|
||||||
|
.getMany()
|
||||||
|
.then((res) => {
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("invites not found", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get invite by id
|
* @description get invite by id
|
||||||
* @param mail string
|
* @param mail string
|
||||||
|
|
6
src/viewmodel/admin/invite.models.ts
Normal file
6
src/viewmodel/admin/invite.models.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export interface InviteViewModel {
|
||||||
|
mail: string;
|
||||||
|
username: string;
|
||||||
|
firstname: string;
|
||||||
|
lastname: string;
|
||||||
|
}
|
Loading…
Reference in a new issue