Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(scripts): add scripts to set student logos to selected forms #2048

Merged
merged 3 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions scripts/20210601_set-rp-sp-student-logos/set-rp-logos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable */

// BEFORE
// A: Count number of forms belonging to RP students.
{
let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id)
db.forms.find({ admin: { $in: rpStudentUserIds } }).count()
}
// Should be 0
{
db.forms.count({
'startPage.logo.fileId': { $eq: '1622549887610-rp%20student%20logo.png' },
})
}

// UPDATE
{
let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id)
let rpStudentFormIds = db.forms.find({ admin: { $in: rpStudentUserIds } }).map(b => b._id)

db.forms.updateMany(
{
_id: { $in: rpStudentFormIds },
},
{
$set: {
'startPage.logo': {
state: 'CUSTOM',
fileId: '1622549887610-rp%20student%20logo.png',
fileName: 'RP Student Logo.png',
fileSizeInBytes: 15242,
},
},
}
)
}

// AFTER

// Number of forms RP's logo fileId. Should be equal to A.
{
db.forms.count({
'startPage.logo.fileId': { $eq: '1622549887610-rp%20student%20logo.png' },
})
}
// Count number of forms belonging to RP students.
// Should still remain the same as A.
{
let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id)
db.forms.find({ admin: { $in: rpStudentUserIds } }).count()
}
42 changes: 42 additions & 0 deletions scripts/20210601_set-rp-sp-student-logos/set-sp-logos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable */

// BEFORE
// A: Count number of forms belonging to SP students.
{
let rpStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id)
db.forms.find({ admin: { $in: rpStudentUserIds } }).count()
}
// Should be 0
{
db.forms.count({ 'startPage.logo.fileId': { $eq: '1622549643061-sp%20student%20logo.png' } })
}

// UPDATE
{
let spStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id)
let spStudentFormIds = db.forms.find({ admin: { $in: spStudentUserIds } }).map(b => b._id)

db.forms.updateMany(
{
_id: { $in: spStudentFormIds }
},
{ $set: { 'startPage.logo': {
"state" : "CUSTOM",
"fileId" : "1622549643061-sp%20student%20logo.png",
"fileName" : "SP Student Logo.png",
"fileSizeInBytes" : 14189
} } }
)
}

// AFTER

// Number of forms SP's logo fileId. Should be equal to A.
{
db.forms.count({ 'startPage.logo.fileId': { $eq: '1622549643061-sp%20student%20logo.png' } })
}
// Should still remain the same as A.
{
let rpStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id)
db.forms.find({ admin: { $in: spStudentUserIds } }).count()
}