Skip to content

Fix: Added organization membership sample data for API_ADMINISTRATOR_USER #3208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/utilities/loadSampleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,50 @@
}),
) as (typeof schema.organizationsTable.$inferInsert)[];
await db.insert(schema.organizationsTable).values(organizations);

// Add API_ADMINISTRATOR_USER_EMAIL_ADDRESS as administrator of the all organization
const API_ADMINISTRATOR_USER_EMAIL_ADDRESS =
process.env.API_ADMINISTRATOR_USER_EMAIL_ADDRESS;
if (!API_ADMINISTRATOR_USER_EMAIL_ADDRESS) {
console.error(
"\x1b[31m",
"API_ADMINISTRATOR_USER_EMAIL_ADDRESS is not defined in .env file",
);
return;
}

Check warning on line 146 in src/utilities/loadSampleData.ts

View check run for this annotation

Codecov / codecov/patch

src/utilities/loadSampleData.ts#L138-L146

Added lines #L138 - L146 were not covered by tests

const API_ADMINISTRATOR_USER = await db.query.usersTable.findFirst({
columns: {
id: true,
},
where: (fields, operators) =>
operators.eq(
fields.emailAddress,
API_ADMINISTRATOR_USER_EMAIL_ADDRESS,
),
});
if (!API_ADMINISTRATOR_USER) {
console.error(
"\x1b[31m",
"API_ADMINISTRATOR_USER_EMAIL_ADDRESS is not found in users table",
);
return;
}

Check warning on line 164 in src/utilities/loadSampleData.ts

View check run for this annotation

Codecov / codecov/patch

src/utilities/loadSampleData.ts#L148-L164

Added lines #L148 - L164 were not covered by tests

const organizationAdminMembership = organizations.map((org) => ({
organizationId: org.id,
memberId: API_ADMINISTRATOR_USER.id,
creatorId: API_ADMINISTRATOR_USER.id,
createdAt: new Date(),
role: "administrator",
})) as (typeof schema.organizationMembershipsTable.$inferInsert)[];
await db
.insert(schema.organizationMembershipsTable)
.values(organizationAdminMembership);
console.log(
"\x1b[35m",
"Added API_ADMINISTRATOR_USER as administrator of the all organization",
);

Check warning on line 179 in src/utilities/loadSampleData.ts

View check run for this annotation

Codecov / codecov/patch

src/utilities/loadSampleData.ts#L166-L179

Added lines #L166 - L179 were not covered by tests
break;
}
case "organization_memberships": {
Expand Down
Loading