68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import { Body, Controller, Get, Param, Patch, Post } from "@nestjs/common";
|
|
import { ok } from "../common/response";
|
|
import { CurrentUser } from "../common/decorators/current-user.decorator";
|
|
import { AcceptHouseholdInviteDto } from "./dto/accept-household-invite.dto";
|
|
import { CreateHouseholdDto } from "./dto/create-household.dto";
|
|
import { CreateHouseholdInviteDto } from "./dto/create-household-invite.dto";
|
|
import { UpdateHouseholdMemberDto } from "./dto/update-household-member.dto";
|
|
import { HouseholdsService } from "./households.service";
|
|
|
|
@Controller("households")
|
|
export class HouseholdsController {
|
|
constructor(private readonly householdsService: HouseholdsService) {}
|
|
|
|
@Get()
|
|
async list(@CurrentUser() userId: string) {
|
|
return ok(await this.householdsService.listForUser(userId));
|
|
}
|
|
|
|
@Post()
|
|
async create(@CurrentUser() userId: string, @Body() payload: CreateHouseholdDto) {
|
|
return ok(await this.householdsService.create(userId, payload));
|
|
}
|
|
|
|
@Get(":id/dashboard")
|
|
async dashboard(@CurrentUser() userId: string, @Param("id") id: string) {
|
|
return ok(await this.householdsService.getDashboard(userId, id));
|
|
}
|
|
|
|
@Get(":id")
|
|
async get(@CurrentUser() userId: string, @Param("id") id: string) {
|
|
return ok(await this.householdsService.getForUser(userId, id));
|
|
}
|
|
|
|
@Get(":id/members")
|
|
async members(@CurrentUser() userId: string, @Param("id") id: string) {
|
|
return ok(await this.householdsService.listMembers(userId, id));
|
|
}
|
|
|
|
@Patch(":id/members/:memberId")
|
|
async updateMember(
|
|
@CurrentUser() userId: string,
|
|
@Param("id") id: string,
|
|
@Param("memberId") memberId: string,
|
|
@Body() payload: UpdateHouseholdMemberDto,
|
|
) {
|
|
return ok(await this.householdsService.updateMember(userId, id, memberId, payload));
|
|
}
|
|
|
|
@Get(":id/invites")
|
|
async invites(@CurrentUser() userId: string, @Param("id") id: string) {
|
|
return ok(await this.householdsService.listInvites(userId, id));
|
|
}
|
|
|
|
@Post(":id/invites")
|
|
async invite(
|
|
@CurrentUser() userId: string,
|
|
@Param("id") id: string,
|
|
@Body() payload: CreateHouseholdInviteDto,
|
|
) {
|
|
return ok(await this.householdsService.invite(userId, id, payload));
|
|
}
|
|
|
|
@Post("invites/accept")
|
|
async acceptInvite(@CurrentUser() userId: string, @Body() payload: AcceptHouseholdInviteDto) {
|
|
return ok(await this.householdsService.acceptInvite(userId, payload));
|
|
}
|
|
}
|