Skip to content

Commit

Permalink
fix: make sure agreements are assigned to reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
Gobot1234 committed Apr 11, 2024
1 parent 10bbe06 commit fd18e0e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions apps/anvil/src/seeder/seeds/users.seed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createHash } from "crypto";
import { readFileSync } from "fs";
import { EdgeDBService } from "@/edgedb/edgedb.service";
import { REP_ON_SHIFT } from "@/sign-in/sign-in.service";
import e from "@dbschema/edgeql-js";

type MigratedUser = {
Expand Down Expand Up @@ -48,20 +49,30 @@ export async function seedUsers(dbService: EdgeDBService) {
userAgreement.length > 0
? userAgreement[0]
: await dbService.query(
e.insert(e.sign_in.Agreement, {
content: readFileSync(ua, { encoding: "utf-8" }),
content_hash: computeFileHash(ua),
}),
e.update(e.sign_in.SignInReason, (reason) => ({
filter_single: e.op(reason.category, "=", e.sign_in.SignInReasonCategory.PERSONAL_PROJECT),
set: {
agreement: e.insert(e.sign_in.Agreement, {
content: readFileSync(ua, { encoding: "utf-8" }),
content_hash: computeFileHash(ua),
}),
},
})),
);

const rep_agreement =
repAgreement.length > 0
? repAgreement[0]
: await dbService.query(
e.insert(e.sign_in.Agreement, {
content: readFileSync(ra, { encoding: "utf-8" }),
content_hash: computeFileHash(ra),
}),
e.update(e.sign_in.SignInReason, (reason) => ({
filter_single: e.op(reason.name, "=", REP_ON_SHIFT),
set: {
agreement: e.insert(e.sign_in.Agreement, {
content: readFileSync(ra, { encoding: "utf-8" }),
content_hash: computeFileHash(ra),
}),
},
})),
);

// Check if mailing list already exists before inserting
Expand Down

0 comments on commit fd18e0e

Please sign in to comment.