feat(client/api): add C# survey (#51682)

This commit is contained in:
Tom
2023-11-07 09:04:12 -06:00
committed by GitHub
parent a297c3b9bb
commit 369368a799
30 changed files with 939 additions and 32 deletions
+43 -1
View File
@@ -10,6 +10,7 @@ const allowedArgs = [
'--donor',
'--top-contributor',
'--unset-privacy-terms',
'--seed-trophy-challenges',
'certified-user'
];
@@ -45,6 +46,45 @@ function handleError(err, client) {
}
}
const trophyChallenges = [
{
id: '647f85d407d29547b3bee1bb',
solution:
'https://learn.microsoft.com/api/gamestatus/achievements/learn.wwl.get-started-c-sharp-part-1.trophy?username=moT01&locale=en-us',
completedDate: 1695064765244
},
{
id: '647f87dc07d29547b3bee1bf',
solution:
'https://learn.microsoft.com/api/gamestatus/achievements/learn.wwl.get-started-c-sharp-part-2.trophy?username=moT01&locale=en-us',
completedDate: 1695064900926
},
{
id: '647f882207d29547b3bee1c0',
solution:
'https://learn.microsoft.com/api/gamestatus/achievements/learn.wwl.get-started-c-sharp-part-3.trophy?username=moT01&locale=en-us',
completedDate: 1695064949460
},
{
id: '647f867a07d29547b3bee1bc',
solution:
'https://learn.microsoft.com/api/gamestatus/achievements/learn.wwl.get-started-c-sharp-part-4.trophy?username=moT01&locale=en-us',
completedDate: 1695064986634
},
{
id: '647f877f07d29547b3bee1be',
solution:
'https://learn.microsoft.com/api/gamestatus/achievements/learn.wwl.get-started-c-sharp-part-5.trophy?username=moT01&locale=en-us',
completedDate: 1695065026465
},
{
id: '647f86ff07d29547b3bee1bd',
solution:
'https://learn.microsoft.com/api/gamestatus/achievements/learn.wwl.get-started-c-sharp-part-6.trophy?username=moT01&locale=en-us',
completedDate: 1695065060157
}
];
const demoUser = {
_id: new ObjectId('5bd30e0f1caf6ac3ddddddb5'),
email: 'foo@bar.com',
@@ -80,7 +120,9 @@ const demoUser = {
isRelationalDatabaseCertV8: false,
isCollegeAlgebraPyCertV8: false,
isFoundationalCSharpCertV8: false,
completedChallenges: [],
completedChallenges: args.includes('--seed-trophy-challenges')
? trophyChallenges
: [],
portfolio: [],
yearsTopContributor: args.includes('--top-contributor')
? ['2017', '2018', '2019']
+99
View File
@@ -0,0 +1,99 @@
const path = require('path');
const debug = require('debug');
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
const { MongoClient, ObjectId } = require('mongodb');
const args = process.argv.slice(2);
const allowedArgs = ['delete-only'];
// Check for invalid arguments
args.forEach(arg => {
if (!allowedArgs.includes(arg))
throw new Error(
`Invalid argument ${arg}. Allowed arguments are ${allowedArgs.join(', ')}`
);
});
const log = debug('fcc:tools:seedSurveyInfo');
const { MONGOHQ_URL } = process.env;
function handleError(err, client) {
if (err) {
console.error('Oh noes!! Error seeding survey info.');
console.error(err);
try {
client.close();
} catch (e) {
// no-op
} finally {
/* eslint-disable-next-line no-process-exit */
process.exit(1);
}
}
}
const surveyIds = [
new ObjectId('651c5a2a5f9b639b584028bc'),
new ObjectId('651c5a4c5f9b639b584028bd')
];
const defaultUserSurvey = {
_id: surveyIds[0],
title: 'Foundational C# with Microsoft Survey',
responses: [
{
question: 'Please describe your role:',
response: 'Beginner developer (less than 2 years experience)'
},
{
question:
'Prior to this course, how experienced were you with .NET and C#?',
response: 'Novice (no prior experience)'
}
],
userId: new ObjectId('5bd30e0f1caf6ac3ddddddb5')
};
const certifiedUserSurvey = {
_id: surveyIds[1],
title: 'Foundational C# with Microsoft Survey',
responses: [
{
question: 'Please describe your role:',
response: 'Experienced developer (more than 5 years experience)'
},
{
question:
'Prior to this course, how experienced were you with .NET and C#?',
response: 'Expert'
}
],
userId: new ObjectId('5fa2db00a25c1c1fa49ce067')
};
const client = new MongoClient(MONGOHQ_URL, { useNewUrlParser: true });
log('Connected successfully to mongo');
const db = client.db('freecodecamp');
const survey = db.collection('Survey');
const run = async () => {
await survey.deleteMany({
_id: {
$in: surveyIds
}
});
log('Survey info deleted');
if (!args.includes('delete-only')) {
await survey.insertOne(defaultUserSurvey);
await survey.insertOne(certifiedUserSurvey);
log('Survey info seeded');
}
};
run()
.then(() => client.close())
.catch(err => handleError(err, client));