Skip to main content

Generate Room/Bedroom STI model

Git Log

commit 73e6c8e00168cf4a7a4409245bd90e8f6aef7386
Author: Daniel Nelson <844258+daniel-nelson@users.noreply.github.com>
Date: Sat Nov 8 11:45:45 2025 -0600

Generate Room/Bedroom STI model

```console
yarn psy g:sti-child Room/Bedroom extends Room bed_types:enum\[\]:bed_types:twin,bunk,queen,king,cot,sofabed

## Diff from 94f272f

```diff
diff --git a/api/spec/factories/Room/BedroomFactory.ts b/api/spec/factories/Room/BedroomFactory.ts
new file mode 100644
index 0000000..0f25e2e
--- /dev/null
+++ b/api/spec/factories/Room/BedroomFactory.ts
@@ -0,0 +1,9 @@
+import { UpdateableProperties } from '@rvoh/dream/types'
+import RoomBedroom from '@models/Room/Bedroom.js'
+
+export default async function createRoomBedroom(attrs: UpdateableProperties<RoomBedroom> = {}) {
+ return await RoomBedroom.create({
+ bedTypes: ['twin'],
+ ...attrs,
+ })
+}
diff --git a/api/spec/unit/models/Room/Bedroom.spec.ts b/api/spec/unit/models/Room/Bedroom.spec.ts
new file mode 100644
index 0000000..89fb496
--- /dev/null
+++ b/api/spec/unit/models/Room/Bedroom.spec.ts
@@ -0,0 +1,3 @@
+describe('Room/Bedroom', () => {
+ it.todo('add a test here to get started building Room/Bedroom')
+})
diff --git a/api/src/app/models/Room/Bedroom.ts b/api/src/app/models/Room/Bedroom.ts
new file mode 100644
index 0000000..b01cab6
--- /dev/null
+++ b/api/src/app/models/Room/Bedroom.ts
@@ -0,0 +1,17 @@
+import { Decorators, STI } from '@rvoh/dream'
+import { DreamColumn, DreamSerializers } from '@rvoh/dream/types'
+import Room from '@models/Room.js'
+
+const deco = new Decorators<typeof RoomBedroom>()
+
+@STI(Room)
+export default class RoomBedroom extends Room {
+ public override get serializers(): DreamSerializers<RoomBedroom> {
+ return {
+ default: 'Room/BedroomSerializer',
+ summary: 'Room/BedroomSummarySerializer',
+ }
+ }
+
+ public bedTypes: DreamColumn<RoomBedroom, 'bedTypes'>
+}
diff --git a/api/src/app/serializers/Room/BedroomSerializer.ts b/api/src/app/serializers/Room/BedroomSerializer.ts
new file mode 100644
index 0000000..e705036
--- /dev/null
+++ b/api/src/app/serializers/Room/BedroomSerializer.ts
@@ -0,0 +1,9 @@
+import { RoomSerializer, RoomSummarySerializer } from '@serializers/RoomSerializer.js'
+import RoomBedroom from '@models/Room/Bedroom.js'
+
+export const RoomBedroomSummarySerializer = (roomBedroom: RoomBedroom) =>
+ RoomSummarySerializer(RoomBedroom, roomBedroom)
+
+export const RoomBedroomSerializer = (roomBedroom: RoomBedroom) =>
+ RoomSerializer(RoomBedroom, roomBedroom)
+ .attribute('bedTypes')
diff --git a/api/src/db/migrations/1762623939899-create-room-bedroom.ts b/api/src/db/migrations/1762623939899-create-room-bedroom.ts
new file mode 100644
index 0000000..55d5d4c
--- /dev/null
+++ b/api/src/db/migrations/1762623939899-create-room-bedroom.ts
@@ -0,0 +1,31 @@
+import { Kysely, sql } from 'kysely'
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export async function up(db: Kysely<any>): Promise<void> {
+ await db.schema
+ .createType('bed_types_enum')
+ .asEnum([
+ 'twin',
+ 'bunk',
+ 'queen',
+ 'king',
+ 'cot',
+ 'sofabed'
+ ])
+ .execute()
+
+ await db.schema
+ .alterTable('rooms')
+ .addColumn('bed_types', sql`bed_types_enum[]`, col => col.notNull().defaultTo('{}'))
+ .execute()
+}
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export async function down(db: Kysely<any>): Promise<void> {
+ await db.schema
+ .alterTable('rooms')
+ .dropColumn('bed_types')
+ .execute()
+
+ await db.schema.dropType('bed_types_enum').execute()
+}
\ No newline at end of file