Skip to content

Commit

Permalink
feat/improve-whitelist-script (#2121)
Browse files Browse the repository at this point in the history
Co-authored-by: Kishen Ashok Kumar <kishenashokkumar@Kishens-MacBook-Pro.local>
  • Loading branch information
KishenKumarrrrr and Kishen Ashok Kumar committed Jul 27, 2023
1 parent 28da770 commit 675cbbd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions backend/src/scripts/insert_experimental_govsg_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type RawOfficerData = {
id?: number
}

const SECTION_DIVIDER =
'\n=============================================================\n'

void (async function main() {
await sequelizeLoader()
const rawDataToInsert = (
Expand Down Expand Up @@ -46,6 +49,7 @@ void (async function main() {
},
},
})
console.log(`Number of users in raw data: ${rawDataToInsert.length}`)
if (domains.length !== rawUniqueDomains.length) {
throw new Error(
`There are missing domains in DB. Needed ${rawUniqueDomains}, Got ${domains.map(
Expand All @@ -61,7 +65,10 @@ void (async function main() {
},
},
})
console.log(SECTION_DIVIDER)
console.log(`Number of existing users: ${existingUsers.length}`)
const existingEmails = existingUsers.map((u) => u.email)
console.log(JSON.stringify(existingEmails, null, 2))
const newUsers = await User.bulkCreate(
rawDataToInsert
.filter((r) => !existingEmails.includes(r.email))
Expand All @@ -73,6 +80,15 @@ void (async function main() {
} as User)
)
)
console.log(SECTION_DIVIDER)
console.log(`Number of new users: ${newUsers.length}`)
console.log(
JSON.stringify(
newUsers.map((i) => i.toJSON()),
null,
2
)
)
const allUsers = [...existingUsers, ...newUsers]
const officersWithIds = rawDataToInsert.map(
(r) =>
Expand All @@ -95,6 +111,11 @@ void (async function main() {
} as UserExperimental)
)
)
console.log(SECTION_DIVIDER)
console.log(
`Number of rows inserted into User Experimental table: ${inserted.length}`
)
console.log('Info inserted into User Experimental table:')
console.log(
JSON.stringify(
inserted.map((i) => i.toJSON()),
Expand All @@ -111,13 +132,19 @@ void (async function main() {
} as GovsgTemplatesAccess)
)
)
console.log(SECTION_DIVIDER)
console.log(
`Number of rows inserted into Govsg Template Access table: ${insertedAccess.length}`
)
console.log('Info inserted into Govsg Template Access table:')
console.log(
JSON.stringify(
insertedAccess.map((i) => i.toJSON()),
null,
2
)
)
console.log(SECTION_DIVIDER)
console.log('Done ✅')
process.exit(0)
})()

0 comments on commit 675cbbd

Please sign in to comment.