Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import { AccessControlModule } from './access-control/access-control.module';
import { WaitlistModule } from './waitlist/waitlist.module';
import { EventsModule } from './events/events.module';
import { MembershipPlansModule } from './membership-plans/membership-plans.module';
import { ShiftsModule } from './shifts/shifts.module';
import { FloorPlanModule } from './floor-plan/floor-plan.module';
import { ReportsModule } from './reports/reports.module';
import { EmailCampaignsModule } from './email-campaigns/email-campaigns.module';
import { InventoryModule } from './inventory/inventory.module';
import { AuditLogModule } from './audit-log/audit-log.module';
Expand Down Expand Up @@ -124,6 +127,9 @@ import { TeamsModule } from './teams/teams.module';
WaitlistModule,
EventsModule,
MembershipPlansModule,
ShiftsModule,
FloorPlanModule,
ReportsModule,
EmailCampaignsModule,
InventoryModule,
AuditLogModule,
Expand Down
19 changes: 19 additions & 0 deletions backend/src/floor-plan/dto/create-floor-plan.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator';

export class CreateFloorPlanDto {
@IsString()
@IsNotEmpty()
name: string;

@IsOptional()
@IsNumber()
canvasWidth?: number;

@IsOptional()
@IsNumber()
canvasHeight?: number;

@IsOptional()
@IsString()
backgroundImageUrl?: string;
}
35 changes: 35 additions & 0 deletions backend/src/floor-plan/dto/save-zones.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Type } from 'class-transformer';
import { IsArray, IsNumber, IsOptional, IsString, IsUUID, ValidateNested } from 'class-validator';

export class ZoneDto {
@IsOptional()
@IsUUID()
workspaceId?: string;

@IsNumber()
x: number;

@IsNumber()
y: number;

@IsNumber()
width: number;

@IsNumber()
height: number;

@IsOptional()
@IsString()
label?: string;

@IsOptional()
@IsString()
color?: string;
}

export class SaveZonesDto {
@IsArray()
@ValidateNested({ each: true })
@Type(() => ZoneDto)
zones: ZoneDto[];
}
42 changes: 42 additions & 0 deletions backend/src/floor-plan/entities/floor-plan-zone.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { FloorPlan } from './floor-plan.entity';

@Entity('floor_plan_zones')
export class FloorPlanZone {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column('uuid')
floorPlanId: string;

@ManyToOne(() => FloorPlan, (fp) => fp.zones, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'floorPlanId' })
floorPlan: FloorPlan;

@Column('uuid', { nullable: true })
workspaceId: string | null;

@Column({ type: 'float' })
x: number;

@Column({ type: 'float' })
y: number;

@Column({ type: 'float' })
width: number;

@Column({ type: 'float' })
height: number;

@Column({ nullable: true })
label: string | null;

@Column({ nullable: true, default: '#6366f1' })
color: string | null;
}
39 changes: 39 additions & 0 deletions backend/src/floor-plan/entities/floor-plan.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
OneToMany,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
import { FloorPlanZone } from './floor-plan-zone.entity';

@Entity('floor_plans')
export class FloorPlan {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
name: string;

@Column({ type: 'int', default: 1200 })
canvasWidth: number;

@Column({ type: 'int', default: 800 })
canvasHeight: number;

@Column({ type: 'text', nullable: true })
backgroundImageUrl: string | null;

@Column({ default: false })
isActive: boolean;

@OneToMany(() => FloorPlanZone, (zone) => zone.floorPlan, { cascade: true })
zones: FloorPlanZone[];

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
71 changes: 71 additions & 0 deletions backend/src/floor-plan/floor-plan.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
Controller,
Get,
Post,
Patch,
Put,
Param,
Body,
UseGuards,
ParseUUIDPipe,
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { FloorPlanService } from './floor-plan.service';
import { CreateFloorPlanDto } from './dto/create-floor-plan.dto';
import { SaveZonesDto } from './dto/save-zones.dto';
import { JwtAuthGuard } from '../auth/guard/jwt.auth.guard';
import { RolesGuard } from '../auth/guard/roles.guard';
import { Roles } from '../auth/decorators/roles.decorators';
import { UserRole } from '../users/enums/userRoles.enum';

@ApiTags('Floor Plan')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Controller('floor-plan')
export class FloorPlanController {
constructor(private readonly service: FloorPlanService) {}

@Post()
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
async create(@Body() dto: CreateFloorPlanDto) {
const data = await this.service.create(dto);
return { message: 'Floor plan created', data };
}

@Get()
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
async findAll() {
const data = await this.service.findAll();
return { data };
}

@Get('active')
async getActive() {
const data = await this.service.getActive();
return { data };
}

@Patch(':id')
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
async update(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: Partial<CreateFloorPlanDto>,
) {
const data = await this.service.update(id, dto);
return { message: 'Floor plan updated', data };
}

@Put(':id/zones')
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
async saveZones(@Param('id', ParseUUIDPipe) id: string, @Body() dto: SaveZonesDto) {
const data = await this.service.saveZones(id, dto);
return { message: 'Zones saved', data };
}

@Patch(':id/activate')
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
async activate(@Param('id', ParseUUIDPipe) id: string) {
const data = await this.service.activate(id);
return { message: 'Floor plan activated', data };
}
}
14 changes: 14 additions & 0 deletions backend/src/floor-plan/floor-plan.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { FloorPlan } from './entities/floor-plan.entity';
import { FloorPlanZone } from './entities/floor-plan-zone.entity';
import { FloorPlanService } from './floor-plan.service';
import { FloorPlanController } from './floor-plan.controller';

@Module({
imports: [TypeOrmModule.forFeature([FloorPlan, FloorPlanZone])],
controllers: [FloorPlanController],
providers: [FloorPlanService],
exports: [FloorPlanService],
})
export class FloorPlanModule {}
55 changes: 55 additions & 0 deletions backend/src/floor-plan/floor-plan.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DataSource, Repository } from 'typeorm';
import { FloorPlan } from './entities/floor-plan.entity';
import { FloorPlanZone } from './entities/floor-plan-zone.entity';
import { CreateFloorPlanDto } from './dto/create-floor-plan.dto';
import { SaveZonesDto } from './dto/save-zones.dto';

@Injectable()
export class FloorPlanService {
constructor(
@InjectRepository(FloorPlan)
private readonly planRepo: Repository<FloorPlan>,
@InjectRepository(FloorPlanZone)
private readonly zoneRepo: Repository<FloorPlanZone>,
private readonly dataSource: DataSource,
) {}

async create(dto: CreateFloorPlanDto): Promise<FloorPlan> {
const plan = this.planRepo.create(dto);
return this.planRepo.save(plan);
}

async update(id: string, dto: Partial<CreateFloorPlanDto>): Promise<FloorPlan> {
const plan = await this.planRepo.findOne({ where: { id } });
if (!plan) throw new NotFoundException(`Floor plan ${id} not found`);
Object.assign(plan, dto);
return this.planRepo.save(plan);
}

async saveZones(id: string, dto: SaveZonesDto): Promise<FloorPlan> {
const plan = await this.planRepo.findOne({ where: { id }, relations: ['zones'] });
if (!plan) throw new NotFoundException(`Floor plan ${id} not found`);
await this.zoneRepo.delete({ floorPlanId: id });
const zones = dto.zones.map((z) => this.zoneRepo.create({ ...z, floorPlanId: id }));
await this.zoneRepo.save(zones);
return this.planRepo.findOne({ where: { id }, relations: ['zones'] }) as Promise<FloorPlan>;
}

async getActive(): Promise<FloorPlan | null> {
return this.planRepo.findOne({ where: { isActive: true }, relations: ['zones'] });
}

async findAll(): Promise<FloorPlan[]> {
return this.planRepo.find({ order: { createdAt: 'DESC' } });
}

async activate(id: string): Promise<FloorPlan> {
await this.planRepo.update({}, { isActive: false });
const plan = await this.planRepo.findOne({ where: { id } });
if (!plan) throw new NotFoundException(`Floor plan ${id} not found`);
plan.isActive = true;
return this.planRepo.save(plan);
}
}
81 changes: 81 additions & 0 deletions backend/src/reports/reports.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Controller, Get, Query, Res, UseGuards } from '@nestjs/common';
import { Response } from 'express';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ReportsService } from './reports.service';
import { JwtAuthGuard } from '../auth/guard/jwt.auth.guard';
import { RolesGuard } from '../auth/guard/roles.guard';
import { Roles } from '../auth/decorators/roles.decorators';
import { UserRole } from '../users/enums/userRoles.enum';

@ApiTags('Reports')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
@Controller('reports')
export class ReportsController {
constructor(private readonly service: ReportsService) {}

@Get('bookings')
async bookings(
@Query('from') from: string,
@Query('to') to: string,
@Query('format') format: string,
@Res({ passthrough: true }) res: Response,
) {
const data = await this.service.bookingsReport(from, to);
if (format === 'csv') {
res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename=bookings.csv');
return this.service.toCsv(data);
}
return { data };
}

@Get('revenue')
async revenue(
@Query('from') from: string,
@Query('to') to: string,
@Query('format') format: string,
@Res({ passthrough: true }) res: Response,
) {
const result = await this.service.revenueReport(from, to);
if (format === 'csv') {
res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename=revenue.csv');
return this.service.toCsv(result.invoices);
}
return { data: result };
}

@Get('members')
async members(
@Query('from') from: string,
@Query('to') to: string,
@Query('format') format: string,
@Res({ passthrough: true }) res: Response,
) {
const result = await this.service.membersReport(from, to);
if (format === 'csv') {
res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename=members.csv');
return this.service.toCsv(result.members);
}
return { data: result };
}

@Get('occupancy')
async occupancy(
@Query('from') from: string,
@Query('to') to: string,
@Query('format') format: string,
@Res({ passthrough: true }) res: Response,
) {
const data = await this.service.occupancyReport(from, to);
if (format === 'csv') {
res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename=occupancy.csv');
return this.service.toCsv(data);
}
return { data };
}
}
15 changes: 15 additions & 0 deletions backend/src/reports/reports.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Booking } from '../bookings/entities/booking.entity';
import { Invoice } from '../invoices/entities/invoice.entity';
import { User } from '../users/entities/user.entity';
import { Workspace } from '../workspaces/entities/workspace.entity';
import { ReportsService } from './reports.service';
import { ReportsController } from './reports.controller';

@Module({
imports: [TypeOrmModule.forFeature([Booking, Invoice, User, Workspace])],
controllers: [ReportsController],
providers: [ReportsService],
})
export class ReportsModule {}
Loading
Loading