-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d47a4c1
commit 35c3218
Showing
8 changed files
with
230 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/extensions/users-permissions/content-types/user/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"kind": "collectionType", | ||
"collectionName": "up_users", | ||
"info": { | ||
"name": "user", | ||
"description": "", | ||
"singularName": "user", | ||
"pluralName": "users", | ||
"displayName": "User" | ||
}, | ||
"options": { | ||
"draftAndPublish": false, | ||
"timestamps": true | ||
}, | ||
"attributes": { | ||
"username": { | ||
"type": "string", | ||
"minLength": 3, | ||
"unique": true, | ||
"configurable": false, | ||
"required": true | ||
}, | ||
"email": { | ||
"type": "email", | ||
"minLength": 6, | ||
"configurable": false, | ||
"required": true | ||
}, | ||
"provider": { | ||
"type": "string", | ||
"configurable": false | ||
}, | ||
"password": { | ||
"type": "password", | ||
"minLength": 6, | ||
"configurable": false, | ||
"private": true | ||
}, | ||
"resetPasswordToken": { | ||
"type": "string", | ||
"configurable": false, | ||
"private": true | ||
}, | ||
"confirmationToken": { | ||
"type": "string", | ||
"configurable": false, | ||
"private": true | ||
}, | ||
"confirmed": { | ||
"type": "boolean", | ||
"default": false, | ||
"configurable": false | ||
}, | ||
"blocked": { | ||
"type": "boolean", | ||
"default": false, | ||
"configurable": false | ||
}, | ||
"role": { | ||
"type": "relation", | ||
"relation": "manyToOne", | ||
"target": "plugin::users-permissions.role", | ||
"inversedBy": "users", | ||
"configurable": false | ||
}, | ||
"challengeCompletions": { | ||
"type": "json", | ||
"required": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { insertPropertiesIf } = require("../utils/general"); | ||
const getChallenges = require("../utils/getChallenges"); | ||
|
||
module.exports = { | ||
queryDefinition: ({ nexus, t }) => { | ||
t.field("getPracticeChallenges", { | ||
type: "GetPracticeChallengesResponse", | ||
args: { | ||
lessonSlug: nexus.stringArg(), | ||
sublessonId: nexus.intArg(), | ||
}, | ||
}); | ||
}, | ||
async resolve(_context, { sublessonId, lessonSlug }) { | ||
console.log("yoo?"); | ||
return { | ||
allChallenges: ( | ||
await getChallenges({ | ||
strapi, | ||
includeTypename: true, | ||
parameters: { | ||
populate: ["challengeMeta.sublesson", "challengeMeta.lesson"], | ||
filters: { | ||
challengeMeta: { | ||
...insertPropertiesIf(sublessonId, { | ||
sublesson: { | ||
id: sublessonId, | ||
}, | ||
}), | ||
...insertPropertiesIf(lessonSlug, { | ||
lesson: { | ||
id: lessonSlug, | ||
}, | ||
}), | ||
}, | ||
}, | ||
}, | ||
}) | ||
).flat(), | ||
recommendedChallenges: sublessonId | ||
? await strapi.db.query("api::sublesson.sublesson").findOne({ | ||
where: { | ||
id: sublessonId, | ||
}, | ||
}) | ||
: [], | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = { | ||
queryDefinition: ({ nexus, t }) => { | ||
t.field("nextLessonSlug", { | ||
type: "String", | ||
args: { | ||
currentLessonId: nexus.intArg(), | ||
}, | ||
}); | ||
}, | ||
async resolve(_context, { currentLessonId }) { | ||
const result = await strapi.db.query("api::module.module").findOne({ | ||
where: { | ||
id: 1, | ||
}, | ||
populate: { | ||
moduleLessons: { | ||
populate: ["lesson"], | ||
}, | ||
}, | ||
}); | ||
const { moduleLessons: lessons } = result; | ||
const currentLessonIndex = lessons.findIndex( | ||
({ lesson: { id } }) => id === currentLessonId | ||
); | ||
|
||
if (currentLessonIndex === -1) { | ||
throw new Error(`Lesson of id ${currentLessonId} not found`); | ||
} | ||
|
||
if (currentLessonIndex === lessons.length - 1) { | ||
return null; | ||
} | ||
|
||
return lessons[currentLessonIndex + 1].lesson.slug; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const challengeTypes = [ | ||
{ | ||
apiReference: "api::code-challenge.code-challenge", | ||
typeName: "CodeChallenge", | ||
}, | ||
{ | ||
apiReference: "api::multiple-choice-challenge.multiple-choice-challenge", | ||
typeName: "MultipleChoiceChallenge", | ||
}, | ||
{ | ||
apiReference: "api::playground.playground", | ||
typeName: "Playground", | ||
}, | ||
]; | ||
|
||
module.exports = async ({ strapi, parameters, includeTypename }) => { | ||
const challengeGroups = await Promise.all( | ||
challengeTypes.map(({ apiReference }) => | ||
strapi.entityService.findMany(apiReference, parameters) | ||
) | ||
); | ||
|
||
const final = includeTypename | ||
? challengeTypes.flatMap(({ typeName }, index) => | ||
challengeGroups[index].map((challenge) => { | ||
return { | ||
...challenge, | ||
challengeType: typeName, | ||
}; | ||
}) | ||
) | ||
: t; | ||
return final; | ||
}; |