Skip to content

Commit

Permalink
add registration to seed
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoalzate committed Jul 25, 2024
1 parent 6296395 commit ff60818
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
randFirstName,
randJobTitle,
randLastName,
randNumber,
randUserName,
randUuid,
} from '@ngneat/falso';
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
import { createInsertSchema } from 'drizzle-zod';
import { z } from 'zod';
import { fieldsSchema, insertOptionsSchema } from '../types';
import { dataSchema, fieldsSchema, insertOptionsSchema } from '../types';
import * as schema from './schema';

// Define the data types for the seed function
Expand All @@ -33,20 +34,30 @@ const insertUsersSchema = createInsertSchema(schema.users);
const insertUsersToGroupsSchema = createInsertSchema(schema.usersToGroups);

async function seed(dbPool: NodePgDatabase<typeof schema>) {
const randId = randUuid();
const randCityFieldId = randUuid();
const randAgeFieldId = randUuid();
const events = await createEvent(dbPool, [
{
name: randCity(),
fields: {
[randId]: {
id: randId,
name: 'submit project',
[randCityFieldId]: {
id: randCityFieldId,
name: 'city',
type: 'TEXT',
position: 0,
validation: {
required: true,
},
},
[randAgeFieldId]: {
id: randAgeFieldId,
name: 'age',
type: 'NUMBER',
position: 0,
validation: {
required: true,
},
},
},
},
]);
Expand Down Expand Up @@ -241,6 +252,28 @@ async function seed(dbPool: NodePgDatabase<typeof schema>) {
},
]);

const registration: z.infer<typeof dataSchema> = {
[randCityFieldId]: {
fieldId: randCityFieldId,
value: randCity(),
type: 'TEXT',
},
[randAgeFieldId]: {
fieldId: randAgeFieldId,
value: randNumber({ min: 18, max: 99 }),
type: 'NUMBER',
},
};

await dbPool
.insert(schema.registrations)
.values({
eventId: events[0]!.id,
userId: users[0]!.id,
data: registration,
})
.returning();

return {
events,
cycles,
Expand Down

0 comments on commit ff60818

Please sign in to comment.