Skip to main content

Generate Guest model

Git Log

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

Generate Guest model

```console
yarn psy g:model Guest User:belongs_to

## Diff from 1374820

```diff
diff --git a/api/spec/factories/GuestFactory.ts b/api/spec/factories/GuestFactory.ts
new file mode 100644
index 0000000..cf2f642
--- /dev/null
+++ b/api/spec/factories/GuestFactory.ts
@@ -0,0 +1,10 @@
+import { UpdateableProperties } from '@rvoh/dream/types'
+import Guest from '@models/Guest.js'
+import createUser from '@spec/factories/UserFactory.js'
+
+export default async function createGuest(attrs: UpdateableProperties<Guest> = {}) {
+ return await Guest.create({
+ user: attrs.user ? null : await createUser(),
+ ...attrs,
+ })
+}
diff --git a/api/spec/unit/models/Guest.spec.ts b/api/spec/unit/models/Guest.spec.ts
new file mode 100644
index 0000000..213d108
--- /dev/null
+++ b/api/spec/unit/models/Guest.spec.ts
@@ -0,0 +1,3 @@
+describe('Guest', () => {
+ it.todo('add a test here to get started building Guest')
+})
diff --git a/api/src/app/models/Guest.ts b/api/src/app/models/Guest.ts
new file mode 100644
index 0000000..d55f5bf
--- /dev/null
+++ b/api/src/app/models/Guest.ts
@@ -0,0 +1,27 @@
+import { Decorators } from '@rvoh/dream'
+import { DreamColumn, DreamSerializers } from '@rvoh/dream/types'
+import ApplicationModel from '@models/ApplicationModel.js'
+import User from '@models/User.js'
+
+const deco = new Decorators<typeof Guest>()
+
+export default class Guest extends ApplicationModel {
+ public override get table() {
+ return 'guests' as const
+ }
+
+ public get serializers(): DreamSerializers<Guest> {
+ return {
+ default: 'GuestSerializer',
+ summary: 'GuestSummarySerializer',
+ }
+ }
+
+ public id: DreamColumn<Guest, 'id'>
+ public createdAt: DreamColumn<Guest, 'createdAt'>
+ public updatedAt: DreamColumn<Guest, 'updatedAt'>
+
+ @deco.BelongsTo('User', { on: 'userId' })
+ public user: User
+ public userId: DreamColumn<Guest, 'userId'>
+}
diff --git a/api/src/app/serializers/GuestSerializer.ts b/api/src/app/serializers/GuestSerializer.ts
new file mode 100644
index 0000000..1fa3936
--- /dev/null
+++ b/api/src/app/serializers/GuestSerializer.ts
@@ -0,0 +1,9 @@
+import { DreamSerializer } from '@rvoh/dream'
+import Guest from '@models/Guest.js'
+
+export const GuestSummarySerializer = (guest: Guest) =>
+ DreamSerializer(Guest, guest)
+ .attribute('id')
+
+export const GuestSerializer = (guest: Guest) =>
+ GuestSummarySerializer(guest)
diff --git a/api/src/db/migrations/1762620340186-create-guest.ts b/api/src/db/migrations/1762620340186-create-guest.ts
new file mode 100644
index 0000000..3edfe7e1
--- /dev/null
+++ b/api/src/db/migrations/1762620340186-create-guest.ts
@@ -0,0 +1,24 @@
+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
+ .createTable('guests')
+ .addColumn('id', 'bigserial', col => col.primaryKey())
+ .addColumn('user_id', 'bigint', col => col.references('users.id').onDelete('restrict').notNull())
+ .addColumn('created_at', 'timestamp', col => col.notNull())
+ .addColumn('updated_at', 'timestamp', col => col.notNull())
+ .execute()
+
+ await db.schema
+ .createIndex('guests_user_id')
+ .on('guests')
+ .column('user_id')
+ .execute()
+}
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export async function down(db: Kysely<any>): Promise<void> {
+ await db.schema.dropIndex('guests_user_id').execute()
+ await db.schema.dropTable('guests').execute()
+}
\ No newline at end of file