secure type with passphrase

This commit is contained in:
Julian Krauser 2024-12-03 19:29:38 +01:00
parent 597feef9ef
commit 8f49533fcb
9 changed files with 44 additions and 2 deletions

View file

@ -2,6 +2,7 @@ export interface CreateCalendarTypeCommand {
type: string;
nscdr: boolean;
color: string;
passphrase?: string;
}
export interface UpdateCalendarTypeCommand {
@ -9,6 +10,7 @@ export interface UpdateCalendarTypeCommand {
type: string;
nscdr: boolean;
color: string;
passphrase?: string;
}
export interface DeleteCalendarTypeCommand {

View file

@ -18,6 +18,7 @@ export default abstract class CalendarTypeCommandHandler {
type: createCalendarType.type,
nscdr: createCalendarType.nscdr,
color: createCalendarType.color,
passphrase: createCalendarType.nscdr ? null : createCalendarType.passphrase,
})
.execute()
.then((result) => {
@ -41,6 +42,7 @@ export default abstract class CalendarTypeCommandHandler {
type: updateCalendarType.type,
nscdr: updateCalendarType.nscdr,
color: updateCalendarType.color,
passphrase: updateCalendarType.nscdr ? null : updateCalendarType.passphrase,
})
.where("id = :id", { id: updateCalendarType.id })
.execute()

View file

@ -101,11 +101,13 @@ export async function createCalendarType(req: Request, res: Response): Promise<a
const type = req.body.type;
const nscdr = req.body.nscdr;
const color = req.body.color;
const passphrase = req.body.passphrase;
let createType: CreateCalendarTypeCommand = {
type,
nscdr,
color,
passphrase,
};
let id = await CalendarTypeCommandHandler.create(createType);
@ -154,12 +156,14 @@ export async function updateCalendarType(req: Request, res: Response): Promise<a
const type = req.body.type;
const nscdr = req.body.nscdr;
const color = req.body.color;
const passphrase = req.body.passphrase;
let updateType: UpdateCalendarTypeCommand = {
id,
type,
nscdr,
color,
passphrase,
};
await CalendarTypeCommandHandler.update(updateType);

View file

@ -9,6 +9,7 @@ import CalendarFactory from "../factory/admin/calendar";
/**
* @description get all calendar items by types or nscdr
* @summary passphrase is passed as value pair like `type:passphrase`
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
@ -22,8 +23,14 @@ export async function getCalendarItemsByTypes(req: Request, res: Response): Prom
}
let items: Array<calendar> = [];
if (types.length == 0) {
let typeIds = await CalendarTypeService.getByTypes(types as Array<string>);
if (types.length != 0) {
let typeIds = await CalendarTypeService.getByTypes((types as Array<string>).map((t) => t.split(":")[0]));
typeIds = typeIds.filter(
(ti) =>
ti.passphrase == null ||
ti.passphrase == "" ||
ti.passphrase == (types as Array<string>).find((t) => t.includes(ti.type)).split(":")[1]
);
items = await CalendarService.getByTypes(typeIds.map((t) => t.id));
} else {
items = await CalendarService.getByTypeNSCDR();

View file

@ -43,6 +43,7 @@ import { Calendar1729947763295 } from "./migrations/1729947763295-calendar";
import { reset } from "./entity/reset";
import { ResetToken1732358596823 } from "./migrations/1732358596823-resetToken";
import { SMSAlarming1732696919191 } from "./migrations/1732696919191-SMSAlarming";
import { SecuringCalendarType1733249553766 } from "./migrations/1733249553766-securingCalendarType";
const dataSource = new DataSource({
type: DB_TYPE as any,
@ -96,6 +97,7 @@ const dataSource = new DataSource({
Calendar1729947763295,
ResetToken1732358596823,
SMSAlarming1732696919191,
SecuringCalendarType1733249553766,
],
migrationsRun: true,
migrationsTransactionMode: "each",

View file

@ -15,6 +15,9 @@ export class calendarType {
@Column({ type: "varchar", length: 255 })
color: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
passphrase: string | null;
@OneToMany(() => calendar, (c) => c.type, {
nullable: false,
onDelete: "RESTRICT",

View file

@ -13,6 +13,7 @@ export default abstract class CalendarTypeFactory {
type: record.type,
nscdr: record.nscdr,
color: record.color,
passphrase: record.passphrase,
};
}

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
export class SecuringCalendarType1733249553766 implements MigrationInterface {
name = "SecuringCalendarType1733249553766";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumns("calendar_type", [
new TableColumn({
name: "passphrase",
type: "varchar",
length: "255",
isNullable: true,
}),
]);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn("calendar_type", "passphrase");
}
}

View file

@ -3,4 +3,5 @@ export interface CalendarTypeViewModel {
type: string;
nscdr: boolean;
color: string;
passphrase: string | null;
}