Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
28 changes: 28 additions & 0 deletions backend/typescript/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable */
require("dotenv").config();

module.exports = {
development: {
username: process.env.POSTGRES_USER || "postgres",
password: process.env.POSTGRES_PASSWORD || "password",
database: process.env.POSTGRES_DB_NAME || "humane_society_dev",
host: process.env.DB_HOST || "db",
port: process.env.DB_PORT || 5432,
dialect: "postgres",
logging: false,
},
test: {
username: process.env.POSTGRES_USER || "postgres",
password: process.env.POSTGRES_PASSWORD || "password",
database: process.env.POSTGRES_DB_TEST || "humane_society_test",
host: process.env.DB_HOST || "db",
port: process.env.DB_PORT || 5432,
dialect: "postgres",
logging: false,
},
production: {
use_env_variable: "DATABASE_URL",
dialect: "postgres",
logging: false,
},
};
7 changes: 6 additions & 1 deletion backend/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"lint": "eslint . --ext .ts,.js",
"fix": "eslint . --ext .ts,.js --fix",
"postinstall": "tsc",
"sequelize": "ts-node ./node_modules/.bin/sequelize-cli"
"sequelize": "ts-node ./node_modules/.bin/sequelize-cli",
"seed": "yarn sequelize db:seed:all",
"start:ts": "ts-node -r dotenv/config server.ts",
"migrate": "yarn sequelize db:migrate",
"seed:undo": "yarn sequelize db:seed:undo:all",
"seed:auth": "ts-node -r dotenv/config scripts/seed-auth-users.ts"
},
"keywords": [],
"author": "",
Expand Down
93 changes: 93 additions & 0 deletions backend/typescript/scripts/seed-auth-users.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document code blocks for clarity

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-disable */
import * as fs from "fs";
import * as path from "path";
import admin from "firebase-admin";
import "dotenv/config";

if (!process.env.FIREBASE_AUTH_EMULATOR_HOST) {
console.error(
"Set FIREBASE_AUTH_EMULATOR_HOST (e.g., host.docker.internal:9099).",
);
process.exit(1);
}

if (!admin.apps.length) {
admin.initializeApp({
projectId: process.env.FIREBASE_PROJECT_ID || "uw-blueprint-starter-code",
});
}

const auth = admin.auth();

const USERS = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place mock data elsewhere and then import for easy editing of mock data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do and will do!

{
label: "admin_001",
email: "john.smith@humanesociety.com",
password: "Passw0rd!",
displayName: "John Smith",
},
{
label: "admin_002",
email: "sarah.johnson@humanesociety.com",
password: "Passw0rd!",
displayName: "Sarah Johnson",
},
{
label: "behaviourist_001",
email: "emily.wilson@humanesociety.com",
password: "Passw0rd!",
displayName: "Emily Wilson",
},
{
label: "behaviourist_002",
email: "michael.brown@humanesociety.com",
password: "Passw0rd!",
displayName: "Michael Brown",
},
{
label: "staff_001",
email: "lisa.davis@humanesociety.com",
password: "Passw0rd!",
displayName: "Lisa Davis",
},
{
label: "staff_002",
email: "robert.miller@humanesociety.com",
password: "Passw0rd!",
displayName: "Robert Miller",
},
{
label: "volunteer_001",
email: "amanda.garcia@volunteer.com",
password: "Passw0rd!",
displayName: "Amanda Garcia",
},
{
label: "volunteer_002",
email: "kevin.martinez@volunteer.com",
password: "Passw0rd!",
displayName: "Kevin Martinez",
},
];

(async () => {
const map: Record<string, string> = {};
for (const u of USERS) {
try {
const ex = await auth.getUserByEmail(u.email);
map[u.label] = ex.uid;
} catch {
const created = await auth.createUser({
email: u.email,
password: u.password,
displayName: u.displayName,
emailVerified: true,
});
map[u.label] = created.uid;
}
}
const outPath = path.resolve(__dirname, "../seeders/seed-auth-map.json");
fs.writeFileSync(outPath, JSON.stringify(map, null, 2));
console.log("Wrote UID map:", outPath, map);
process.exit(0);
})();
145 changes: 145 additions & 0 deletions backend/typescript/seeders/20251023-01-seed-users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* eslint-disable */
import type { QueryInterface } from "sequelize";
import { resolveTable, tsKeys, withTS, Rec } from "../utilities/_utils";

// Pull real UIDs created by `yarn seed:auth`
let uidMap: Record<string, string>;
try {
uidMap = require("./seed-auth-map.json");
} catch {
throw new Error(
"seed-auth-map.json not found. Run `docker compose exec ts-backend yarn seed:auth` first.",
);
}

module.exports = {
up: async (queryInterface: QueryInterface) => {
const Users = await resolveTable(queryInterface, ["Users", "users"]);
const uTS = await tsKeys(queryInterface, Users);

const users: Rec[] = [
{
first_name: "John",
last_name: "Smith",
auth_id: uidMap.admin_001,
role: "Administrator",
email: "john.smith@humanesociety.com",
color_level: 5,
animal_tags: "{Dog,Cat}",
status: "Active",
can_see_all_logs: true,
can_assign_users_to_tasks: true,
phone_number: "+1-555-0101",
},
{
first_name: "Sarah",
last_name: "Johnson",
auth_id: uidMap.admin_002,
role: "Administrator",
email: "sarah.johnson@humanesociety.com",
color_level: 5,
animal_tags: "{Bird,Small Animal}",
status: "Active",
can_see_all_logs: true,
can_assign_users_to_tasks: true,
phone_number: "+1-555-0102",
},
{
first_name: "Emily",
last_name: "Wilson",
auth_id: uidMap.behaviourist_001,
role: "Animal Behaviourist",
email: "emily.wilson@humanesociety.com",
color_level: 5,
animal_tags: "{Dog,Cat,Small Animal}",
status: "Active",
can_see_all_logs: true,
can_assign_users_to_tasks: false,
phone_number: "+1-555-0201",
},
{
first_name: "Michael",
last_name: "Brown",
auth_id: uidMap.behaviourist_002,
role: "Animal Behaviourist",
email: "michael.brown@humanesociety.com",
color_level: 4,
animal_tags: "{Bird,Bunny}",
status: "Active",
can_see_all_logs: true,
can_assign_users_to_tasks: false,
phone_number: "+1-555-0202",
},
{
first_name: "Lisa",
last_name: "Davis",
auth_id: uidMap.staff_001,
role: "Staff",
email: "lisa.davis@humanesociety.com",
color_level: 4,
animal_tags: "{Dog,Cat}",
status: "Active",
can_see_all_logs: false,
can_assign_users_to_tasks: true,
phone_number: "+1-555-0301",
},
{
first_name: "Robert",
last_name: "Miller",
auth_id: uidMap.staff_002,
role: "Staff",
email: "robert.miller@humanesociety.com",
color_level: 3,
animal_tags: "{Bunny,Small Animal}",
status: "Active",
can_see_all_logs: false,
can_assign_users_to_tasks: true,
phone_number: "+1-555-0302",
},
{
first_name: "Amanda",
last_name: "Garcia",
auth_id: uidMap.volunteer_001,
role: "Volunteer",
email: "amanda.garcia@volunteer.com",
color_level: 2,
animal_tags: "{Dog}",
status: "Active",
can_see_all_logs: false,
can_assign_users_to_tasks: false,
phone_number: "+1-555-0401",
},
{
first_name: "Kevin",
last_name: "Martinez",
auth_id: uidMap.volunteer_002,
role: "Volunteer",
email: "kevin.martinez@volunteer.com",
color_level: 1,
animal_tags: "{Cat,Bird}",
status: "Active",
can_see_all_logs: false,
can_assign_users_to_tasks: false,
phone_number: "+1-555-0402",
},
].map((r) => withTS(r, uTS.createdKey, uTS.updatedKey));

await queryInterface.bulkInsert(Users, users);
},

down: async (queryInterface: QueryInterface) => {
const Users = await resolveTable(queryInterface, ["Users", "users"]);
await queryInterface.bulkDelete(Users, {
auth_id: [
uidMap.admin_001,
uidMap.admin_002,
uidMap.behaviourist_001,
uidMap.behaviourist_002,
uidMap.staff_001,
uidMap.staff_002,
uidMap.volunteer_001,
uidMap.volunteer_002,
],
} as any);
},
};
Loading