import { Share } from '@fastify-modular/route'; import { pito } from 'pito'; import { DealState, DealStateEvent } from '../enums'; // ========================================================================== export const EventSystemPayload = pito.Uobj('type') // 회원가입 관련 .case('register', ({})) // 중개회원 관련 .case('broker-accept', ({})) .case('broker-reject', ({})) // 매물등록 관련 .case('create-sell', ({sellId: pito.Int()})) .case('create-buy', ({buyId: pito.Int()})) // 등록된 매물에 구매요청 .case('request-buy', ({sellId: pito.Int(), buyId: pito.Int()})) // 계약서 관련 .case('create-deal', ({dealId: pito.Int()})) .case('update-deal', ({ dealId: pito.Int(), prev : DealState, event : DealStateEvent, curr : DealState, })) // 단순 시스템 알림 .case('notify', ({message: pito.Str()})) // 채팅방 생성 요청 .case('connect-chatroom', ({roomId: pito.UUID()})) .end(); export type EventSystemPayload = pito.Type; // ========================================================================== export const EventChatPayload = pito.Uobj('type') .case('enter', ({who: pito.Obj({id: pito.Int(), name: pito.Str()}), at: pito.Datetime()})) .case('broadcast', ({at: pito.Datetime(), content: pito.Str(), sender: pito.Obj({id: pito.Int(), name: pito.Str()})})) .case('exit', ({who: pito.Obj({id: pito.Int(), name: pito.Str()}), at: pito.Datetime()})) .end(); export type EventChatPayload = pito.Type; // ========================================================================== export const EventPayload = pito.Uobj('namespace') .case('chat', {msgId: pito.UUID(), roomId: pito.UUID(), event: EventChatPayload}) .case('system', {msgId: pito.UUID(), roomId: pito.UUID(), event: EventSystemPayload}) .end(); export type EventPayload = pito.Type; // ========================================================================== export const Event = Share(`/event/user/:userId`) .params(pito.Obj({ userId: pito.Num(), })) .payload(EventPayload) .build(); // ==========================================================================