diff --git a/public/admin.html b/public/admin.html index 11815ba..982123e 100644 --- a/public/admin.html +++ b/public/admin.html @@ -74,10 +74,6 @@ -
- - -
{{ loginMessage }}
@@ -96,10 +92,6 @@ -
- - -
{{ registerMessage }}
@@ -110,7 +102,7 @@
{{ user?.name || user?.email }}
-
Tenant: {{ tenantId }}
+
Tenant: unificado
@@ -174,15 +166,15 @@ const token = ref(localStorage.getItem(tokenKey) || ''); const user = ref(null); - const tenantId = ref('default'); + const tenantId = ref('default'); // kept for compatibility (subdomain / future use) const status = ref(''); const modules = ref([]); const selectedModule = ref(''); const moduleHtml = ref(''); const loading = ref(false); - const login = reactive({ email: '', password: '', tenantId: 'default' }); - const register = reactive({ name: '', email: '', password: '', tenantId: 'default' }); + const login = reactive({ email: '', password: '' }); + const register = reactive({ name: '', email: '', password: '' }); const loginMessage = ref(''); const loginError = ref(false); @@ -203,8 +195,7 @@ setStatus('Consultando ' + path + '...'); const headers = options.headers || {}; if (token.value) headers.Authorization = `Bearer ${token.value}`; - headers['x-tenant-id'] = tenantId.value || 'default'; - const res = await fetch(`${apiRoot}${path}?tenantId=${encodeURIComponent(tenantId.value)}`, { + const res = await fetch(`${apiRoot}${path}`, { ...options, headers, }); @@ -236,7 +227,6 @@ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - tenantId: login.tenantId || 'default', email: login.email, password: login.password, }), @@ -270,7 +260,6 @@ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - tenantId: register.tenantId || 'default', name: register.name, email: register.email, password: register.password, diff --git a/src/admin/admin.controller.ts b/src/admin/admin.controller.ts index ef1cd89..24fa6d7 100644 --- a/src/admin/admin.controller.ts +++ b/src/admin/admin.controller.ts @@ -4,8 +4,6 @@ import { GuestService } from '../guest/services/guest.service'; import { TodoService } from '../todo/services/todo.service'; import { ModuleRegistryService } from '../core/services/module-registry.service'; -const DEFAULT_TENANT = process.env.DEFAULT_TENANT_ID ?? 'default'; - @Controller('admin') export class AdminController { constructor( @@ -20,94 +18,64 @@ export class AdminController { return this.moduleRegistry.getModules(); } - private getTenantId(tenantId?: string) { - return tenantId ?? DEFAULT_TENANT; - } - // Guests @Get('guest') - listGuests(@Query('tenantId') tenantId?: string) { - return this.guestService.listGuests(this.getTenantId(tenantId)); + listGuests() { + return this.guestService.listGuests(); } @Post('guest') - createGuest( - @Query('tenantId') tenantId: string, - @Body() body: any, - ) { - return this.guestService.createGuest(this.getTenantId(tenantId), body as any); + createGuest(@Body() body: any) { + return this.guestService.createGuest(body as any); } @Patch('guest/:id/rsvp') - updateGuestRsvp( - @Query('tenantId') tenantId: string, - @Param('id') id: string, - @Body() body: any, - ) { - return this.guestService.updateRsvp(this.getTenantId(tenantId), id, body as any); + updateGuestRsvp(@Param('id') id: string, @Body() body: any) { + return this.guestService.updateRsvp(id, body as any); } // Todos @Get('todo') - listTodos(@Query('tenantId') tenantId?: string) { - return this.todoService.listTodos(this.getTenantId(tenantId)); + listTodos() { + return this.todoService.listTodos(); } @Post('todo') - createTodo( - @Query('tenantId') tenantId: string, - @Body() body: Record, - ) { - return this.todoService.createTodo(this.getTenantId(tenantId), body); + createTodo(@Body() body: Record) { + return this.todoService.createTodo(body); } @Patch('todo/:id/complete') - completeTodo( - @Query('tenantId') tenantId: string, - @Param('id') id: string, - ) { - return this.todoService.markComplete(this.getTenantId(tenantId), id); + completeTodo(@Param('id') id: string) { + return this.todoService.markComplete(id); } // Gifts @Get('gift') - listGifts(@Query('tenantId') tenantId?: string) { - return this.giftService.listGifts(this.getTenantId(tenantId)); + listGifts() { + return this.giftService.listGifts(); } @Post('gift') - createGift( - @Query('tenantId') tenantId: string, - @Body() body: any, - ) { - return this.giftService.createGift(this.getTenantId(tenantId), body as any); + createGift(@Body() body: any) { + return this.giftService.createGift(body as any); } @Get('gift/:id') - getGift( - @Query('tenantId') tenantId: string, - @Param('id') id: string, - ) { - return this.giftService.getGiftById(this.getTenantId(tenantId), id); + getGift(@Param('id') id: string) { + return this.giftService.getGiftById(id); } @Post('gift/:id/contribution') - createContribution( - @Query('tenantId') tenantId: string, - @Param('id') id: string, - @Body() body: any, - ) { - return this.giftService.createContribution(this.getTenantId(tenantId), { + createContribution(@Param('id') id: string, @Body() body: any) { + return this.giftService.createContribution({ ...(body as any), giftId: id, }); } @Get('gift/:id/contributions') - listContributions( - @Query('tenantId') tenantId: string, - @Param('id') id: string, - ) { - return this.giftService.listContributions(this.getTenantId(tenantId), id); + listContributions(@Param('id') id: string) { + return this.giftService.listContributions(id); } } diff --git a/src/core/api/auth.controller.ts b/src/core/api/auth.controller.ts index 721d7d8..a4ba9d3 100644 --- a/src/core/api/auth.controller.ts +++ b/src/core/api/auth.controller.ts @@ -13,22 +13,19 @@ export class AuthController { async register( @Body() body: { - tenantId?: string; name?: string; email: string; password: string; }, ) { - const tenantId = body.tenantId || process.env.DEFAULT_TENANT_ID || 'default'; + const tenantId = process.env.DEFAULT_TENANT_ID || 'default'; const user = await this.userService.createUser(tenantId, body.email, body.password, body.name); return { id: user.id, email: user.email, name: user.name }; } @Post('login') - async login( - @Body() body: { tenantId?: string; email: string; password: string }, - ) { - const tenantId = body.tenantId || process.env.DEFAULT_TENANT_ID || 'default'; + async login(@Body() body: { email: string; password: string }) { + const tenantId = process.env.DEFAULT_TENANT_ID || 'default'; const user = await this.userService.validateUser(tenantId, body.email, body.password); if (!user) { return { message: 'Invalid credentials' }; diff --git a/src/gift/services/gift.service.ts b/src/gift/services/gift.service.ts index 35b3b71..1c07f5f 100644 --- a/src/gift/services/gift.service.ts +++ b/src/gift/services/gift.service.ts @@ -16,9 +16,14 @@ export class GiftService { return this.orm.em.fork(); } - async createGift(tenantId: string, dto: CreateGiftDto): Promise { + private getTenantId(): string { + // Tenant is now fixed; multi-tenant handled by reverse proxy (subdomains) + return process.env.DEFAULT_TENANT_ID || 'default'; + } + + async createGift(dto: CreateGiftDto): Promise { const gift = this.em.create(Gift, { - tenantId, + tenantId: this.getTenantId(), ...dto, } as any); this.em.persist(gift); @@ -27,9 +32,9 @@ export class GiftService { return gift; } - async createContribution(tenantId: string, dto: CreateContributionDto): Promise { + async createContribution(dto: CreateContributionDto): Promise { const contribution = this.em.create(GiftContribution, { - tenantId, + tenantId: this.getTenantId(), ...dto, } as any); this.em.persist(contribution); @@ -38,16 +43,15 @@ export class GiftService { return contribution; } - async listGifts(tenantId: string): Promise { - return this.em.find(Gift, { tenantId }); + async listGifts(): Promise { + return this.em.find(Gift, { tenantId: this.getTenantId() }); } async getGiftById( - tenantId: string, id: string, requesterId?: string, ): Promise { - const gift = await this.em.findOne(Gift, { tenantId, id }); + const gift = await this.em.findOne(Gift, { tenantId: this.getTenantId(), id }); if (!gift) return null; if (requesterId && gift.ownerId && gift.ownerId !== requesterId) { return null; @@ -56,12 +60,11 @@ export class GiftService { } async listContributions( - tenantId: string, giftId: string, requesterId?: string, ): Promise { - const gift = await this.getGiftById(tenantId, giftId, requesterId); + const gift = await this.getGiftById(giftId, requesterId); if (!gift) return []; - return this.em.find(GiftContribution, { tenantId, giftId }); + return this.em.find(GiftContribution, { tenantId: this.getTenantId(), giftId }); } } diff --git a/src/guest/services/guest.service.ts b/src/guest/services/guest.service.ts index bfc9b4d..0ae2e68 100644 --- a/src/guest/services/guest.service.ts +++ b/src/guest/services/guest.service.ts @@ -16,9 +16,14 @@ export class GuestService { return this.orm.em.fork(); } - async createGuest(tenantId: string, dto: CreateGuestDto): Promise { + private getTenantId(): string { + // Tenant is now fixed; multi-tenant will be handled by routing (subdomains) later. + return process.env.DEFAULT_TENANT_ID || 'default'; + } + + async createGuest(dto: CreateGuestDto): Promise { const guest = this.em.create(Guest, { - tenantId, + tenantId: this.getTenantId(), ...dto, } as any); this.em.persist(guest); @@ -27,8 +32,8 @@ export class GuestService { return guest; } - async updateRsvp(tenantId: string, guestId: string, dto: UpdateRsvpDto): Promise { - const guest = await this.em.findOne(Guest, { tenantId, id: guestId }); + async updateRsvp(guestId: string, dto: UpdateRsvpDto): Promise { + const guest = await this.em.findOne(Guest, { tenantId: this.getTenantId(), id: guestId }); if (!guest) return null; guest.rsvp = dto.rsvp; if (dto.tableId) { @@ -40,7 +45,7 @@ export class GuestService { return guest; } - async listGuests(tenantId: string): Promise { - return this.em.find(Guest, { tenantId }); + async listGuests(): Promise { + return this.em.find(Guest, { tenantId: this.getTenantId() }); } } diff --git a/src/todo/services/todo.service.ts b/src/todo/services/todo.service.ts index 0255b24..0aefc64 100644 --- a/src/todo/services/todo.service.ts +++ b/src/todo/services/todo.service.ts @@ -14,9 +14,14 @@ export class TodoService { return this.orm.em.fork(); } - async createTodo(tenantId: string, dto: Partial): Promise { + private getTenantId(): string { + // Tenant is now fixed; multi-tenant handled by reverse proxy (subdomains) + return process.env.DEFAULT_TENANT_ID || 'default'; + } + + async createTodo(dto: Partial): Promise { const todo = this.em.create(TodoItem, { - tenantId, + tenantId: this.getTenantId(), ...dto, } as any); this.em.persist(todo); @@ -25,12 +30,12 @@ export class TodoService { return todo; } - async listTodos(tenantId: string): Promise { - return this.em.find(TodoItem, { tenantId }); + async listTodos(): Promise { + return this.em.find(TodoItem, { tenantId: this.getTenantId() }); } - async markComplete(tenantId: string, id: string): Promise { - const todo = await this.em.findOne(TodoItem, { tenantId, id }); + async markComplete(id: string): Promise { + const todo = await this.em.findOne(TodoItem, { tenantId: this.getTenantId(), id }); if (!todo) return null; todo.completed = true; this.em.persist(todo);