4 Commits

13 changed files with 213 additions and 55 deletions

16
.vscode/settings.json vendored
View File

@@ -1,5 +1,19 @@
{
"editor.fontFamily": "'FiraCode Nerd Font Mono',Menlo, Monaco, 'Courier New', monospace",
"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"
}
]
}

View File

@@ -1,6 +1,7 @@
<form [formGroup]="filterForm" class="p-4 bg-base-200 rounded-lg shadow">
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-end">
<div class="form-control"><label class="label"><span class="label-text">SearchTerm</span></label>
<input type="text" formControlName="term" class="input input-bordered w-full" placeholder="Search term" /></div>
<div class="form-control"><label class="label"><span class="label-text">Keresés</span></label>
<input type="text" formControlName="term" class="input input-bordered w-full" placeholder="Keresés" />
</div>
</div>
</form>
</form>

View File

@@ -36,10 +36,15 @@ export class SingleEventDashboardEventActivation {
const event = this.event();
console.info('setEventOccurrenceActivation', event);
const eventId = this.event()?.id!;
const startTime = this.event()?.startTime!;
const eventId = event?.id!;
const originalStartTime = event?.originalStartTime!;
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) {
payload = {
...eventException,
@@ -50,7 +55,7 @@ export class SingleEventDashboardEventActivation {
};
} else {
payload = {
originalStartTime: new Date(startTime),
originalStartTime: new Date(originalStartTime),
isCancelled: !activated,
};
}

View File

@@ -16,7 +16,7 @@ export type BookingWithUserDto = {
id: number;
};
export interface EventExceptionDto{
export interface EventExceptionDto {
id: number,
description: string;
eventId: number;
@@ -33,6 +33,7 @@ export type CalendarEventDto = {
id: number;
title: string;
startTime: string,
originalStartTime: string,
endTime: string,
description: string,
isModified?: boolean;

View File

@@ -5,28 +5,35 @@
<div class="card bg-base-100 shadow-xl max-w-2xl mx-auto">
<div class="card-body">
<h2 class="card-title text-3xl">
{{ isEditMode ? 'Edit' : 'Create' }} EventType
{{ isEditMode ? 'Frissítés' : 'Létrehozás' }} Esemény típus
</h2>
<form [formGroup]="form" (ngSubmit)="onSubmit()" class="space-y-4 mt-4">
<div class="form-control"><label class="label"><span class="label-text">Esemény típus neve</span></label>
<input type="text" formControlName="name" class="input input-bordered w-full" /></div>
<div class="form-control"><label class="label"><span class="label-text">Esemény típus neve</span></label>
<input type="text" formControlName="name" class="input input-bordered w-full" />
</div>
<div class="form-control"><label class="label"><span class="label-text">Leírás</span></label>
<input type="text" formControlName="description" class="input input-bordered w-full" /></div>
<div class="form-control"><label class="label"><span class="label-text">Leírás</span></label>
<input type="text" formControlName="description" class="input input-bordered w-full" />
</div>
<div class="form-control"><label class="label"><span class="label-text">Szín</span></label>
<input type="color" formControlName="color" class="input input-bordered w-full" colorspace="display-p3"
alpha /></div>
<div class="form-control"><label class="label"><span class="label-text">Szín</span></label>
<input type="color" formControlName="color" class="input input-bordered w-full" colorspace="display-p3"
alpha />
</div>
<div class="form-control"><label class="label"><span class="label-text">Maximális slot szám</span></label>
<input type="number" formControlName="max_slot_count" class="input input-bordered w-full" />
</div>
<div class="card-actions justify-end mt-6">
<a routerLink="/event-type" class="btn btn-ghost">Cancel</a>
<a routerLink="/event-type" class="btn btn-ghost">Vissza</a>
<button type="submit" class="btn btn-primary" [disabled]="form.invalid">
{{ isEditMode ? 'Update' : 'Create' }}
{{ isEditMode ? 'Frissítés' : 'Létrehozás' }}
</button>
</div>
</form>
</div>
</div>
</div>
</div>

View File

@@ -33,7 +33,7 @@ export class EventTypeFormComponent implements OnInit {
isEditMode = false;
id: number | null = null;
private numericFields = [];
private numericFields = ['max_slot_count'];
constructor(
private fb: FormBuilder,
@@ -43,9 +43,10 @@ export class EventTypeFormComponent implements OnInit {
private cdr: ChangeDetectorRef
) {
this.form = this.fb.group({
name: [null],
description: [null],
color: [null]
name: [null],
description: [null],
color: [null],
max_slot_count: [null]
});
}
@@ -89,22 +90,22 @@ export class EventTypeFormComponent implements OnInit {
const payload = { ...this.form.value };
for (const field of this.numericFields) {
if (payload[field] != null && payload[field] !== '') {
payload[field] = parseFloat(payload[field]);
}
}
for (const field of this.numericFields) {
if (payload[field] != null && payload[field] !== '') {
payload[field] = parseFloat(payload[field]);
}
}
let action$: Observable<EventType>;
if (this.isEditMode && this.id) {
if (this.isEditMode && this.id) {
action$ = this.eventTypeService.update(this.id, payload);
} else {
action$ = this.eventTypeService.create(payload);
}
action$.subscribe({
next: () => this.router.navigate(['/event-type']),
next: () => this.router.navigate(['/event-type/table']),
error: (err) => console.error('Failed to save event-type', err)
});
}

View File

@@ -13,19 +13,21 @@
<table class="table w-full">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>description</th>
<th>color</th>
<th class="text-right">Actions</th>
<th>Azonosító</th>
<th>Név</th>
<th>Leírás</th>
<th>Szín</th>
<th>Férőhelyek</th>
<th class="text-right">Műveletek</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of response.data" class="hover">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.description }}</td>
<td>{{ item.color }}</td>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.description }}</td>
<td>{{ item.color }}</td>
<td>{{ item.max_slot_count }}</td>
<td class="text-right space-x-2">
<a [routerLink]="['/event-type', item.id]" class="btn btn-sm btn-ghost">Részletek</a>
<a [routerLink]="['/event-type', item.id, 'edit']" class="btn btn-sm btn-ghost">Módosítás</a>
@@ -33,7 +35,7 @@
</td>
</tr>
<tr *ngIf="response.data.length === 0">
<td colspan="5" class="text-center">No event-type found.</td>
<td colspan="6" class="text-center">Nem található eseménytípusok.</td>
</tr>
</tbody>
</table>
@@ -42,14 +44,10 @@
<!-- Pagination Controls -->
<div *ngIf="response.meta.totalPages > 1" class="flex justify-center mt-4">
<div class="join">
<button
class="join-item btn"
(click)="changePage(response.meta.currentPage - 1)"
<button class="join-item btn" (click)="changePage(response.meta.currentPage - 1)"
[disabled]="response.meta.currentPage === 1">«</button>
<button class="join-item btn">Page {{ response.meta.currentPage }} of {{ response.meta.totalPages }}</button>
<button
class="join-item btn"
(click)="changePage(response.meta.currentPage + 1)"
<button class="join-item btn">Oldal {{ response.meta.currentPage }} of {{ response.meta.totalPages }}</button>
<button class="join-item btn" (click)="changePage(response.meta.currentPage + 1)"
[disabled]="response.meta.currentPage === response.meta.totalPages">»</button>
</div>
</div>
@@ -60,4 +58,4 @@
<span class="loading loading-spinner loading-lg"></span>
</div>
</ng-template>
</div>
</div>

View File

@@ -60,7 +60,7 @@ export class EventTypeTableComponent implements OnInit {
columns: [
{
attribute: 'name',
headerCell: true,
headerCell: { value: 'Név' },
valueCell: {
styleClass: ctx => 'w-[1%]',
value: item => item?.name,
@@ -68,14 +68,14 @@ export class EventTypeTableComponent implements OnInit {
},
{
attribute: 'description',
headerCell: true,
headerCell: { value: 'Leírás' },
valueCell: {
value: item => item?.description,
},
},
{
attribute: 'color',
headerCell: true,
headerCell: { value: 'Szín' },
valueCell: {
styleClass: ctx => 'w-[1%]',
value: item => item?.color,
@@ -85,9 +85,16 @@ export class EventTypeTableComponent implements OnInit {
}
},
},
{
attribute: 'max_slot_count',
headerCell: { value: 'Férőhelyek' },
valueCell: {
value: item => item?.max_slot_count,
},
},
{
attribute: 'actions',
headerCell: { value: 'Actions' },
headerCell: { value: 'Műveletek' },
valueCell: {
styleClass: ctx => 'w-[1%]',
component: GenericActionColumn,

View File

@@ -6,6 +6,7 @@ export interface EventType {
name: string;
description: string;
color: string;
max_slot_count?: number;
}
export interface PaginatedResponse<T> {

View File

@@ -62,10 +62,10 @@ type BookingWithUserDto = {
id: number;
};
// The final shape of a calendar event occurrence
export type CalendarEventDto = Omit<Event, 'bookings'> & {
isModified?: boolean;
isCancelled?: boolean;
originalStartTime: Date;
eventBookings: BookingWithUserDto[];
};
@@ -146,6 +146,7 @@ export class CalendarService {
const key = `${event.id}-${event.startTime.getTime()}`;
return {
...event,
originalStartTime: event.startTime,
eventBookings: bookingMap.get(key) || [],
};
});
@@ -197,6 +198,7 @@ export class CalendarService {
exception.newEndTime ||
new Date(occurrenceDate.getTime() + duration),
isModified: true,
originalStartTime: occurrenceDate,
eventBookings: bookingMap.get(key) || [],
isCancelled: !!exception.isCancelled,
});
@@ -206,6 +208,7 @@ export class CalendarService {
recurringOccurrences.push({
...event,
startTime: occurrenceDate,
originalStartTime: occurrenceDate,
endTime: new Date(occurrenceDate.getTime() + duration),
eventBookings: bookingMap.get(key) || [],
});

View File

@@ -2,7 +2,7 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { Event } from './event.entity';
import { IsString, IsOptional } from 'class-validator';
import { IsString, IsOptional, IsNumber } from 'class-validator';
@Entity({ name: 'event_type' })
export class EventType {
@@ -23,6 +23,11 @@ export class EventType {
@IsString()
color: string | null;
@Column({ type: 'integer', nullable: true })
@IsOptional()
@IsNumber()
max_slot_count: number | null;
@OneToMany(() => Event, (event) => event.eventType)
events: Event[];
}

View 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.
}
}

View File

@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddMaxSlotCountToEventType1763106308125 implements MigrationInterface {
name = 'AddMaxSlotCountToEventType1763106308125';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "event_type" ADD COLUMN "max_slot_count" integer NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "event_type" DROP COLUMN "max_slot_count"`);
}
}