Initial commit: HOA Financial Intelligence Platform MVP
Multi-tenant financial management platform for homeowner associations featuring: - NestJS backend with 16 modules (auth, accounts, transactions, budgets, units, invoices, payments, vendors, reserves, investments, capital projects, reports) - React + Mantine frontend with dashboard, CRUD pages, and financial reports - Schema-per-tenant PostgreSQL isolation with JWT-based tenant resolution - Docker Compose infrastructure (nginx, backend, frontend, postgres, redis) - Comprehensive seed data for Sunrise Valley HOA demo - 39 API endpoints with Swagger documentation - Double-entry bookkeeping with journal entries - Budget vs actual reporting and Sankey cash flow visualization Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
24
backend/src/modules/units/units.controller.ts
Normal file
24
backend/src/modules/units/units.controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Controller, Get, Post, Put, Body, Param, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { UnitsService } from './units.service';
|
||||
|
||||
@ApiTags('units')
|
||||
@Controller('units')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class UnitsController {
|
||||
constructor(private unitsService: UnitsService) {}
|
||||
|
||||
@Get()
|
||||
findAll() { return this.unitsService.findAll(); }
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) { return this.unitsService.findOne(id); }
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: any) { return this.unitsService.create(dto); }
|
||||
|
||||
@Put(':id')
|
||||
update(@Param('id') id: string, @Body() dto: any) { return this.unitsService.update(id, dto); }
|
||||
}
|
||||
10
backend/src/modules/units/units.module.ts
Normal file
10
backend/src/modules/units/units.module.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UnitsController } from './units.controller';
|
||||
import { UnitsService } from './units.service';
|
||||
|
||||
@Module({
|
||||
controllers: [UnitsController],
|
||||
providers: [UnitsService],
|
||||
exports: [UnitsService],
|
||||
})
|
||||
export class UnitsModule {}
|
||||
51
backend/src/modules/units/units.service.ts
Normal file
51
backend/src/modules/units/units.service.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common';
|
||||
import { TenantService } from '../../database/tenant.service';
|
||||
|
||||
@Injectable()
|
||||
export class UnitsService {
|
||||
constructor(private tenant: TenantService) {}
|
||||
|
||||
async findAll() {
|
||||
return this.tenant.query(`
|
||||
SELECT u.*,
|
||||
COALESCE((
|
||||
SELECT SUM(i.amount - i.amount_paid)
|
||||
FROM invoices i
|
||||
WHERE i.unit_id = u.id AND i.status NOT IN ('paid', 'void', 'written_off')
|
||||
), 0) as balance_due
|
||||
FROM units u ORDER BY u.unit_number
|
||||
`);
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const rows = await this.tenant.query('SELECT * FROM units WHERE id = $1', [id]);
|
||||
if (!rows.length) throw new NotFoundException('Unit not found');
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
async create(dto: any) {
|
||||
const existing = await this.tenant.query('SELECT id FROM units WHERE unit_number = $1', [dto.unit_number]);
|
||||
if (existing.length) throw new BadRequestException(`Unit ${dto.unit_number} already exists`);
|
||||
|
||||
const rows = await this.tenant.query(
|
||||
`INSERT INTO units (unit_number, address_line1, city, state, zip_code, owner_name, owner_email, owner_phone, monthly_assessment)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *`,
|
||||
[dto.unit_number, dto.address_line1, dto.city, dto.state, dto.zip_code, dto.owner_name, dto.owner_email, dto.owner_phone, dto.monthly_assessment || 0],
|
||||
);
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
async update(id: string, dto: any) {
|
||||
await this.findOne(id);
|
||||
const rows = await this.tenant.query(
|
||||
`UPDATE units SET unit_number = COALESCE($2, unit_number), address_line1 = COALESCE($3, address_line1),
|
||||
city = COALESCE($4, city), state = COALESCE($5, state), zip_code = COALESCE($6, zip_code),
|
||||
owner_name = COALESCE($7, owner_name), owner_email = COALESCE($8, owner_email),
|
||||
owner_phone = COALESCE($9, owner_phone), monthly_assessment = COALESCE($10, monthly_assessment),
|
||||
status = COALESCE($11, status), updated_at = NOW()
|
||||
WHERE id = $1 RETURNING *`,
|
||||
[id, dto.unit_number, dto.address_line1, dto.city, dto.state, dto.zip_code, dto.owner_name, dto.owner_email, dto.owner_phone, dto.monthly_assessment, dto.status],
|
||||
);
|
||||
return rows[0];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user