-
Notifications
You must be signed in to change notification settings - Fork 2
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
6343794
commit 1cc113a
Showing
64 changed files
with
361 additions
and
741 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
16 changes: 0 additions & 16 deletions
16
apps/api/src/app/controllers/quests/custom/custom.router.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
apps/api/src/app/controllers/quests/custom/entries/post.controller.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
apps/api/src/app/controllers/quests/daily/entries/post.controller.ts
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
apps/api/src/app/controllers/quests/entries/post.controller.ts
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,59 @@ | ||
import { Request, Response } from 'express'; | ||
import { body, param } from 'express-validator'; | ||
import { NotFoundError } from '@thxnetwork/api/util/errors'; | ||
import { JobType, QuestVariant } from '@thxnetwork/common/enums'; | ||
import { agenda } from '@thxnetwork/api/util/agenda'; | ||
import QuestService from '@thxnetwork/api/services/QuestService'; | ||
import { questInteractionVariantMap } from '@thxnetwork/common/maps/quest'; | ||
import { QuestSocial } from '@thxnetwork/api/models'; | ||
|
||
const validation = [param('variant').isString(), param('id').isMongoId(), body('recaptcha').isString()]; | ||
|
||
// Dynamically create a map from string to enum value | ||
const stringToEnumMap = Object.keys(QuestVariant) | ||
.filter((key) => isNaN(Number(key))) // Filter out the reverse mapping keys | ||
.reduce((acc, key) => { | ||
acc[key.toLowerCase()] = QuestVariant[key as keyof typeof QuestVariant]; | ||
return acc; | ||
}, {} as Record<string, QuestVariant>); | ||
|
||
// Get enum variant for param string or find social variant by quest id | ||
async function getVariantFromParams(params: { variant: string; id: string }) { | ||
const variant = stringToEnumMap[params.variant.toLowerCase()] as QuestVariant; | ||
if (typeof variant === 'undefined') { | ||
const quest = await QuestSocial.findById(params.id); | ||
return quest && questInteractionVariantMap[quest.interaction]; | ||
} | ||
return variant; | ||
} | ||
|
||
const controller = async (req: Request, res: Response) => { | ||
const { params, account } = req; | ||
const variant = await getVariantFromParams({ variant: params.variant, id: params.id }); | ||
if (typeof variant === 'undefined') throw new NotFoundError('Could not determine the quest variant'); | ||
|
||
const quest = await QuestService.findById(variant, params.id); | ||
if (!quest) throw new NotFoundError('Could not find the quest'); | ||
|
||
const data = await QuestService.getDataForRequest(variant, req, { quest, account }); | ||
const validationResult = await QuestService.getValidationResult(variant, { | ||
quest, | ||
account, | ||
data, | ||
}); | ||
if (!validationResult.result) return res.json({ error: validationResult.reason }); | ||
|
||
const job = await agenda.now(JobType.CreateQuestEntry, { | ||
variant, | ||
questId: quest.id, | ||
sub: account.sub, | ||
data: { | ||
...data, | ||
metadata: validationResult, | ||
}, | ||
}); | ||
|
||
res.json({ jobId: job.attrs._id }); | ||
}; | ||
|
||
export { controller, validation }; |
50 changes: 0 additions & 50 deletions
50
apps/api/src/app/controllers/quests/gitcoin/entries/post.controller.ts
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
apps/api/src/app/controllers/quests/gitcoin/gitcoin.router.ts
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
apps/api/src/app/controllers/quests/invite/entries/post.controller.ts
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
apps/api/src/app/controllers/quests/invite/invite.router.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.