Compare commits
2 Commits
7ed3367ed8
...
df35b8991d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df35b8991d | ||
|
|
4349fa39b4 |
16
.vscode/settings.json
vendored
16
.vscode/settings.json
vendored
@@ -1,5 +1,19 @@
|
|||||||
{
|
{
|
||||||
"editor.fontFamily": "'FiraCode Nerd Font Mono',Menlo, Monaco, 'Courier New', monospace",
|
"editor.fontFamily": "'FiraCode Nerd Font Mono',Menlo, Monaco, 'Courier New', monospace",
|
||||||
"terminal.integrated.fontFamily": "'FiraCode Nerd Font Mono'",
|
"terminal.integrated.fontFamily": "'FiraCode Nerd Font Mono'",
|
||||||
"markdown.preview.fontFamily": "'FiraCode Nerd Font Mono',-apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif"
|
"markdown.preview.fontFamily": "'FiraCode Nerd Font Mono',-apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif",
|
||||||
|
"sqltools.connections": [
|
||||||
|
{
|
||||||
|
"ssh": "Disabled",
|
||||||
|
"previewLimit": 50,
|
||||||
|
"server": "localhost",
|
||||||
|
"port": 4301,
|
||||||
|
"driver": "PostgreSQL",
|
||||||
|
"name": "dvbooking-dev",
|
||||||
|
"group": "dvbooking",
|
||||||
|
"database": "dvbooking",
|
||||||
|
"username": "postgres",
|
||||||
|
"password": "test"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -36,10 +36,15 @@ export class SingleEventDashboardEventActivation {
|
|||||||
|
|
||||||
const event = this.event();
|
const event = this.event();
|
||||||
console.info('setEventOccurrenceActivation', event);
|
console.info('setEventOccurrenceActivation', event);
|
||||||
const eventId = this.event()?.id!;
|
const eventId = event?.id!;
|
||||||
const startTime = this.event()?.startTime!;
|
const originalStartTime = event?.originalStartTime!;
|
||||||
let payload: CreateExceptionDto | undefined;
|
let payload: CreateExceptionDto | undefined;
|
||||||
const eventException = event?.exceptions?.length ? event.exceptions[0] : undefined;
|
|
||||||
|
// Correctly find the exception that matches this specific occurrence
|
||||||
|
const eventException = event?.exceptions?.find(ex =>
|
||||||
|
new Date(ex.originalStartTime).getTime() === new Date(originalStartTime).getTime()
|
||||||
|
);
|
||||||
|
|
||||||
if (eventException) {
|
if (eventException) {
|
||||||
payload = {
|
payload = {
|
||||||
...eventException,
|
...eventException,
|
||||||
@@ -50,7 +55,7 @@ export class SingleEventDashboardEventActivation {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
payload = {
|
payload = {
|
||||||
originalStartTime: new Date(startTime),
|
originalStartTime: new Date(originalStartTime),
|
||||||
isCancelled: !activated,
|
isCancelled: !activated,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export type CalendarEventDto = {
|
|||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
startTime: string,
|
startTime: string,
|
||||||
|
originalStartTime: string,
|
||||||
endTime: string,
|
endTime: string,
|
||||||
description: string,
|
description: string,
|
||||||
isModified?: boolean;
|
isModified?: boolean;
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ type BookingWithUserDto = {
|
|||||||
id: number;
|
id: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The final shape of a calendar event occurrence
|
|
||||||
export type CalendarEventDto = Omit<Event, 'bookings'> & {
|
export type CalendarEventDto = Omit<Event, 'bookings'> & {
|
||||||
isModified?: boolean;
|
isModified?: boolean;
|
||||||
isCancelled?: boolean;
|
isCancelled?: boolean;
|
||||||
|
originalStartTime: Date;
|
||||||
eventBookings: BookingWithUserDto[];
|
eventBookings: BookingWithUserDto[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,6 +146,7 @@ export class CalendarService {
|
|||||||
const key = `${event.id}-${event.startTime.getTime()}`;
|
const key = `${event.id}-${event.startTime.getTime()}`;
|
||||||
return {
|
return {
|
||||||
...event,
|
...event,
|
||||||
|
originalStartTime: event.startTime,
|
||||||
eventBookings: bookingMap.get(key) || [],
|
eventBookings: bookingMap.get(key) || [],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -197,6 +198,7 @@ export class CalendarService {
|
|||||||
exception.newEndTime ||
|
exception.newEndTime ||
|
||||||
new Date(occurrenceDate.getTime() + duration),
|
new Date(occurrenceDate.getTime() + duration),
|
||||||
isModified: true,
|
isModified: true,
|
||||||
|
originalStartTime: occurrenceDate,
|
||||||
eventBookings: bookingMap.get(key) || [],
|
eventBookings: bookingMap.get(key) || [],
|
||||||
isCancelled: !!exception.isCancelled,
|
isCancelled: !!exception.isCancelled,
|
||||||
});
|
});
|
||||||
@@ -206,6 +208,7 @@ export class CalendarService {
|
|||||||
recurringOccurrences.push({
|
recurringOccurrences.push({
|
||||||
...event,
|
...event,
|
||||||
startTime: occurrenceDate,
|
startTime: occurrenceDate,
|
||||||
|
originalStartTime: occurrenceDate,
|
||||||
endTime: new Date(occurrenceDate.getTime() + duration),
|
endTime: new Date(occurrenceDate.getTime() + duration),
|
||||||
eventBookings: bookingMap.get(key) || [],
|
eventBookings: bookingMap.get(key) || [],
|
||||||
});
|
});
|
||||||
|
|||||||
100
server/src/migration/1763106308124-add_non_admin_users.ts
Normal file
100
server/src/migration/1763106308124-add_non_admin_users.ts
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddNonAdminUsers1763106308124 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
// 1. Create 'user' Role if it doesn't exist
|
||||||
|
const roles = await queryRunner.query(
|
||||||
|
`SELECT id FROM "user_role" WHERE "name" = 'user'`,
|
||||||
|
);
|
||||||
|
let userRoleId: number;
|
||||||
|
if (roles.length === 0) {
|
||||||
|
const insertRole = await queryRunner.query(
|
||||||
|
`INSERT INTO "user_role" ("name") VALUES ('user') RETURNING id`,
|
||||||
|
);
|
||||||
|
userRoleId = insertRole[0].id;
|
||||||
|
} else {
|
||||||
|
userRoleId = roles[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Create 'user' Group if it doesn't exist
|
||||||
|
const groups = await queryRunner.query(
|
||||||
|
`SELECT id FROM "user_group" WHERE "name" = 'user'`,
|
||||||
|
);
|
||||||
|
let userGroupId: number;
|
||||||
|
if (groups.length === 0) {
|
||||||
|
const insertGroup = await queryRunner.query(
|
||||||
|
`INSERT INTO "user_group" ("name") VALUES ('user') RETURNING id`,
|
||||||
|
);
|
||||||
|
userGroupId = insertGroup[0].id;
|
||||||
|
} else {
|
||||||
|
userGroupId = groups[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Link Group to Role if not linked
|
||||||
|
const groupRoles = await queryRunner.query(
|
||||||
|
`SELECT * FROM "user_group_roles_user_role" WHERE "userGroupId" = $1 AND "userRoleId" = $2`,
|
||||||
|
[userGroupId, userRoleId],
|
||||||
|
);
|
||||||
|
if (groupRoles.length === 0) {
|
||||||
|
await queryRunner.query(
|
||||||
|
`INSERT INTO "user_group_roles_user_role" ("userGroupId", "userRoleId") VALUES ($1, $2)`,
|
||||||
|
[userGroupId, userRoleId],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Create 3 Users
|
||||||
|
const passwordHash = '$2a$12$sT7bIBfUdAvCzcwyppSX/uVd4EP6ORgWiEg7jqXvMKJErR5jWhnmO'; // '123456'
|
||||||
|
const usersToCreate = [
|
||||||
|
{ username: 'user1', email: 'user1@test.com' },
|
||||||
|
{ username: 'user2', email: 'user2@test.com' },
|
||||||
|
{ username: 'user3', email: 'user3@test.com' },
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const userData of usersToCreate) {
|
||||||
|
const existingUser = await queryRunner.query(
|
||||||
|
`SELECT id FROM "user" WHERE "username" = $1`,
|
||||||
|
[userData.username],
|
||||||
|
);
|
||||||
|
|
||||||
|
let userId: number;
|
||||||
|
if (existingUser.length === 0) {
|
||||||
|
const insertUser = await queryRunner.query(
|
||||||
|
`INSERT INTO "user" ("username", "email", "password") VALUES ($1, $2, $3) RETURNING id`,
|
||||||
|
[userData.username, userData.email, passwordHash],
|
||||||
|
);
|
||||||
|
userId = insertUser[0].id;
|
||||||
|
} else {
|
||||||
|
userId = existingUser[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Link User to Group
|
||||||
|
const userToGroup = await queryRunner.query(
|
||||||
|
`SELECT * FROM "user_groups_user_group" WHERE "userId" = $1 AND "userGroupId" = $2`,
|
||||||
|
[userId, userGroupId],
|
||||||
|
);
|
||||||
|
if (userToGroup.length === 0) {
|
||||||
|
await queryRunner.query(
|
||||||
|
`INSERT INTO "user_groups_user_group" ("userId", "userGroupId") VALUES ($1, $2)`,
|
||||||
|
[userId, userGroupId],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
const usernames = ['user1', 'user2', 'user3'];
|
||||||
|
|
||||||
|
for (const username of usernames) {
|
||||||
|
const user = await queryRunner.query(`SELECT id FROM "user" WHERE "username" = $1`, [username]);
|
||||||
|
if (user.length > 0) {
|
||||||
|
const userId = user[0].id;
|
||||||
|
await queryRunner.query(`DELETE FROM "user_groups_user_group" WHERE "userId" = $1`, [userId]);
|
||||||
|
await queryRunner.query(`DELETE FROM "user" WHERE "id" = $1`, [userId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We might not want to delete the 'user' group and role as they might be used by others,
|
||||||
|
// but for completeness of this migration's "down" if they were created here:
|
||||||
|
// However, usually it's safer to just leave the schema-level definitions if they are generic.
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user