Skip to content

Commit

Permalink
fix(scripts): lowercase email to avoid duplicate (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleynguyen committed Jul 24, 2023
1 parent 51232b2 commit b5a0675
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions backend/src/scripts/insert_experimental_govsg_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Op } from 'sequelize'
import csv from 'csvtojson'
import { UserExperimental } from '@core/models/user/user-experimental'
import { ChannelType } from '@core/constants'
import { GovsgTemplatesAccess } from '@govsg/models'

type RawOfficerData = {
name: string
Expand All @@ -30,7 +31,7 @@ void (async function main() {
(r) =>
({
name: r[0],
email: r[1],
email: r[1].toLowerCase(),
designation: r[2],
agency: r[3],
} as RawOfficerData)
Expand All @@ -47,7 +48,9 @@ void (async function main() {
})
if (domains.length !== rawUniqueDomains.length) {
throw new Error(
`There are missing domains in DB. Needed ${rawUniqueDomains}, Got ${domains}`
`There are missing domains in DB. Needed ${rawUniqueDomains}, Got ${domains.map(
(d) => d.domain
)}`
)
}

Expand Down Expand Up @@ -92,7 +95,29 @@ void (async function main() {
} as UserExperimental)
)
)
console.log(inserted.map((i) => i.toJSON()))
console.log(
JSON.stringify(
inserted.map((i) => i.toJSON()),
null,
2
)
)
const insertedAccess = await GovsgTemplatesAccess.bulkCreate(
allUsers.map(
(u) =>
({
userId: u.id,
templateId: 1,
} as GovsgTemplatesAccess)
)
)
console.log(
JSON.stringify(
insertedAccess.map((i) => i.toJSON()),
null,
2
)
)
console.log('Done ✅')
process.exit(0)
})()

0 comments on commit b5a0675

Please sign in to comment.