Skip to content

Commit

Permalink
Find users by email instead of hard coded userIds. Also simplify seed…
Browse files Browse the repository at this point in the history
…ing script
  • Loading branch information
Greenheart committed Sep 25, 2024
1 parent c83b139 commit 1f4d39a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
19 changes: 1 addition & 18 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,8 @@ async function common() {
return Promise.all([seedGicsCodes(), seedUsers()])
}

async function development() {
await common()
}

async function test() {
await common()
}

async function main() {
switch (process.env.NODE_ENV) {
case 'development':
await development()
break
case 'test':
await test()
break
default:
break
}
common()
}

main()
Expand Down
4 changes: 2 additions & 2 deletions scripts/import-spreadsheet-companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const ENV = envSchema.parse(process.env)

const USERS = {
garbo: {
id: 1,
email: '[email protected]',
token: ENV.API_TOKENS.garbo,
},
alex: {
id: 2,
email: '[email protected]',
token: ENV.API_TOKENS.alex,
},
}
Expand Down
14 changes: 7 additions & 7 deletions src/routes/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const cache = () => {
}

const USERS = {
garbo: 1,
alex: 2,
garbo: '[email protected]',
alex: '[email protected]',
}

export const fakeAuth =
Expand All @@ -55,7 +55,7 @@ export const fakeAuth =
if (ENV.API_TOKENS.includes(token)) {
const [username] = token.split(':')
const user = await prisma.user.findFirst({
where: { id: USERS[username] },
where: { email: USERS[username] },
})
res.locals.user = user
}
Expand Down Expand Up @@ -93,8 +93,8 @@ export const createMetadata =
if (req.method === 'POST') {
// TODO: Find a better way to determine if changes by the current user should count as verified or not
// IDEA: Maybe a column in the User table to determine if this is a trusted editor? And if so, all their changes are automatically "verified".
const verifiedByUserId =
res.locals.user.id === USERS.alex ? USERS.alex : null
const verifiedByUserEmail =
res.locals.user.email === USERS.alex ? USERS.alex : null

const { comment, source, dataOrigin } = req.body.metadata ?? {}

Expand All @@ -108,10 +108,10 @@ export const createMetadata =
id: res.locals.user.id,
},
},
verifiedBy: verifiedByUserId
verifiedBy: verifiedByUserEmail
? {
connect: {
id: verifiedByUserId,
email: verifiedByUserEmail,
},
}
: undefined,
Expand Down

0 comments on commit 1f4d39a

Please sign in to comment.