Skip to content

Commit 0e7d64d

Browse files
authored
Merge pull request #4295 from Northeastern-Electric-Racing/#4240-shop-machinery-data
#4240 Generate Shop and Machinery
2 parents 8d92f94 + 57348d6 commit 0e7d64d

5 files changed

Lines changed: 162 additions & 9 deletions

File tree

src/backend/src/prisma/dev-seed.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { UsersProcess } from './seed/user.process.js';
1111
import { OrganizationProcess } from './seed/organization.process.js';
1212
import { CarProcess } from './seed/car.process.js';
1313
import { ConfigDataProcess } from './seed/config-data.process.js';
14+
import { ShopProcess } from './seed/shop.process.js';
1415
import { TeamProcess } from './seed/team.process.js';
1516
import { SchedulingProcess } from './seed/scheduling.process.js';
1617

@@ -25,7 +26,8 @@ await new SeedRunner()
2526
new UsersProcess(),
2627
new ConfigDataProcess(),
2728
new SchedulingProcess(),
28-
new TeamProcess()
29+
new TeamProcess(),
30+
new ShopProcess()
2931
)
3032
.run();
3133

src/backend/src/prisma/factories/config-data.factory.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import { Prisma } from '@prisma/client';
2+
import { connectOrganization, connectUser } from '../utils/common.factory.js';
23

34
const SEED_CREATED_AT = new Date('2024-01-01T00:00:00.000Z');
45

5-
const connectOrganization = (organizationId: string) => ({
6-
connect: { organizationId }
7-
});
8-
9-
const connectUser = (userId: string) => ({
10-
connect: { userId }
11-
});
12-
136
export const teamTypeCreateInputs = (organizationId: string): Prisma.Team_TypeCreateInput[] => [
147
{
158
name: 'Mechanical',
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { Prisma } from '@prisma/client';
2+
import { connectUser, connectOrganization } from '../utils/common.factory.js';
3+
4+
type ShopConfig = {
5+
name: string;
6+
description: string;
7+
};
8+
9+
type MachineryConfig = {
10+
name: string;
11+
shopName: string;
12+
quantity: number;
13+
};
14+
15+
export const shopConfigs: ShopConfig[] = [
16+
{ name: 'Forsyth Machine Shop', description: 'MIE Club Machine Shop' },
17+
{ name: 'Richards 054', description: 'Main Richards Makerspace' },
18+
{ name: 'Richards 055', description: 'Richards Basement Shop' },
19+
{ name: 'Richards 050', description: 'THE BAYYYYYY WOOOO' }, // Fire description
20+
{ name: 'EXP Machine Shop', description: 'Basement of EXP' }
21+
];
22+
23+
export const machineryConfigs: MachineryConfig[] = [
24+
// Forsyth Machine Shop
25+
{ name: 'Front Tormach 1100MX', shopName: 'Forsyth Machine Shop', quantity: 1 },
26+
{ name: 'Middle Tormach 1100MX', shopName: 'Forsyth Machine Shop', quantity: 1 },
27+
{ name: 'Rear Tormach 1100MX', shopName: 'Forsyth Machine Shop', quantity: 1 },
28+
{ name: 'Right Tormach 1100MX', shopName: 'Forsyth Machine Shop', quantity: 1 },
29+
{ name: 'Front Manual Mill', shopName: 'Forsyth Machine Shop', quantity: 1 },
30+
{ name: 'Rear Manual Mill', shopName: 'Forsyth Machine Shop', quantity: 1 },
31+
{ name: 'Front Manual Lathe', shopName: 'Forsyth Machine Shop', quantity: 1 },
32+
{ name: 'ProtoTRAK CNC Lathe', shopName: 'Forsyth Machine Shop', quantity: 1 },
33+
{ name: 'Tormach 24R CNC Router', shopName: 'Forsyth Machine Shop', quantity: 1 },
34+
{ name: 'Haas VF2 YT', shopName: 'Forsyth Machine Shop', quantity: 1 },
35+
{ name: 'Cold Cut Saw', shopName: 'Forsyth Machine Shop', quantity: 1 },
36+
{ name: 'Rear Manual Lathe', shopName: 'Forsyth Machine Shop', quantity: 1 },
37+
{ name: 'Vertical Bandsaw', shopName: 'Forsyth Machine Shop', quantity: 1 },
38+
{ name: 'Horizontal Bandsaw', shopName: 'Forsyth Machine Shop', quantity: 1 },
39+
40+
// Richards 054
41+
{ name: 'Hydraulic Press', shopName: 'Richards 054', quantity: 1 },
42+
{ name: 'Arbor Press (Baja)', shopName: 'Richards 054', quantity: 1 },
43+
{ name: 'Sheet Metal Brake', shopName: 'Richards 054', quantity: 1 },
44+
45+
// Richards 055
46+
{ name: 'Protomax Waterjet', shopName: 'Richards 055', quantity: 1 },
47+
{ name: 'Drill Press', shopName: 'Richards 055', quantity: 1 },
48+
{ name: 'Belt/Rotary Sander', shopName: 'Richards 055', quantity: 1 },
49+
{ name: 'Bench Grinder', shopName: 'Richards 055', quantity: 2 },
50+
{ name: 'Vertical Bandsaw', shopName: 'Richards 055', quantity: 1 },
51+
{ name: 'Horizontal Bandsaw', shopName: 'Richards 055', quantity: 1 },
52+
53+
// Richards 050
54+
{ name: 'Bambu Lab P1P', shopName: 'Richards 050', quantity: 1 },
55+
{ name: 'Bambu Lab H2S', shopName: 'Richards 050', quantity: 1 },
56+
57+
// EXP Machine Shop
58+
{ name: 'Tormach 1100MX', shopName: 'EXP Machine Shop', quantity: 1 },
59+
{ name: 'Omax Waterjet', shopName: 'EXP Machine Shop', quantity: 1 }
60+
];
61+
62+
export const shopCreateInput = (
63+
userCreatedId: string,
64+
organizationId: string,
65+
config: ShopConfig
66+
): Prisma.ShopCreateInput => ({
67+
name: config.name,
68+
description: config.description,
69+
userCreated: connectUser(userCreatedId),
70+
organization: connectOrganization(organizationId)
71+
});
72+
73+
export const machineryCreateInput = (
74+
userCreatedId: string,
75+
organizationId: string,
76+
config: MachineryConfig
77+
): Prisma.MachineryCreateInput => ({
78+
name: config.name,
79+
userCreated: connectUser(userCreatedId),
80+
organization: connectOrganization(organizationId)
81+
});
82+
83+
export const shopMachineryCreateInput = (
84+
shopId: string,
85+
machineryId: string,
86+
quantity: number
87+
): Prisma.Shop_MachineryCreateInput => ({
88+
shop: { connect: { shopId } },
89+
machinery: { connect: { machineryId } },
90+
quantity
91+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Machinery, Shop, Shop_Machinery } from '@prisma/client';
2+
import { OrganizationOutput, OrganizationProcess } from './organization.process.js';
3+
import { UsersOutput, UsersProcess } from './user.process.js';
4+
import {
5+
machineryConfigs,
6+
machineryCreateInput,
7+
shopConfigs,
8+
shopCreateInput,
9+
shopMachineryCreateInput
10+
} from '../factories/shop.factory.js';
11+
import { SeedProcess } from '../processes/seed-process.js';
12+
13+
type ShopInput = OrganizationOutput & UsersOutput;
14+
15+
export type ShopOutput = {
16+
shops: Shop[];
17+
machinery: Machinery[];
18+
shopMachinery: Shop_Machinery[];
19+
};
20+
21+
export class ShopProcess extends SeedProcess<ShopInput, ShopOutput> {
22+
dependencies() {
23+
return [OrganizationProcess, UsersProcess];
24+
}
25+
26+
async run({ organization, appAdmins }: ShopInput): Promise<ShopOutput> {
27+
const { organizationId } = organization;
28+
const [creator] = appAdmins;
29+
30+
if (!creator) throw new Error('ShopProcess requires at least one app admin user.');
31+
32+
const shops = await Promise.all(
33+
shopConfigs.map((config) =>
34+
this.prisma.shop.create({
35+
data: shopCreateInput(creator.userId, organizationId, config)
36+
})
37+
)
38+
);
39+
40+
const shopIdsByName = shops.reduce<Record<string, string>>((acc, shop) => {
41+
acc[shop.name] = shop.shopId;
42+
return acc;
43+
}, {});
44+
45+
const machinery = await Promise.all(
46+
machineryConfigs.map((config) =>
47+
this.prisma.machinery.create({
48+
data: machineryCreateInput(creator.userId, organizationId, config)
49+
})
50+
)
51+
);
52+
53+
const shopMachinery = await Promise.all(
54+
machineryConfigs.map((config, i) => {
55+
const shopId = shopIdsByName[config.shopName];
56+
if (!shopId) throw new Error(`Missing shop for machinery: ${config.shopName}`);
57+
return this.prisma.shop_Machinery.create({
58+
data: shopMachineryCreateInput(shopId, machinery[i].machineryId, config.quantity)
59+
});
60+
})
61+
);
62+
63+
return { shops, machinery, shopMachinery };
64+
}
65+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const connectUser = (userId: string) => ({ connect: { userId } });
2+
export const connectOrganization = (organizationId: string) => ({ connect: { organizationId } });

0 commit comments

Comments
 (0)