The overall GET / implies that this gets overall registration status, but this does not include drafts. Even if we have two collections under the hood (which we shouldn't but that's a different discussion), callers should not have to choose which collection to pull from. Maybe return something like:
{
submitted: True,
data: ...
}
|
registrationRouter.get( |
|
"/", |
|
specification({ |
|
method: "get", |
|
path: "/registration/", |
|
tag: Tag.REGISTRATION, |
|
role: Role.USER, |
|
summary: "Gets the currently authenticated user's submitted registration data", |
|
responses: { |
|
[StatusCode.SuccessOK]: { |
|
description: "The submitted registration information", |
|
schema: RegistrationApplicationDraftSchema, |
|
}, |
|
[StatusCode.ClientErrorNotFound]: { |
|
description: "Couldn't find submitted registration information (make sure you create it first!)", |
|
schema: RegistrationNotFoundErrorSchema, |
|
}, |
|
}, |
|
}), |
|
async (req, res) => { |
|
const { id: userId } = getAuthenticatedUser(req); |
|
|
|
const registrationData = await Models.RegistrationApplicationSubmitted.findOne({ userId }); |
|
if (!registrationData) { |
|
return res.status(StatusCode.ClientErrorNotFound).send(RegistrationNotFoundError); |
|
} |
|
|
|
return res.status(StatusCode.SuccessOK).send(registrationData); |
|
}, |
|
); |
|
|
|
registrationRouter.get( |
|
"/draft/", |
|
specification({ |
|
method: "get", |
|
path: "/registration/draft/", |
|
tag: Tag.REGISTRATION, |
|
role: Role.USER, |
|
summary: "Gets the currently authenticated user's draft registration data", |
|
responses: { |
|
[StatusCode.SuccessOK]: { |
|
description: "The draft registration information", |
|
schema: RegistrationApplicationDraftSchema, |
|
}, |
|
[StatusCode.ClientErrorNotFound]: { |
|
description: "Couldn't find draft registration information (make sure you create it first!)", |
|
schema: RegistrationNotFoundErrorSchema, |
|
}, |
|
}, |
|
}), |
|
async (req, res) => { |
|
const { id: userId } = getAuthenticatedUser(req); |
|
|
|
const registrationData = await Models.RegistrationApplicationDraft.findOne({ userId }); |
|
if (!registrationData) { |
|
return res.status(StatusCode.ClientErrorNotFound).send(RegistrationNotFoundError); |
|
} |
|
|
|
return res.status(StatusCode.SuccessOK).send(registrationData); |
|
}, |
|
); |
The overall
GET /implies that this gets overall registration status, but this does not include drafts. Even if we have two collections under the hood (which we shouldn't but that's a different discussion), callers should not have to choose which collection to pull from. Maybe return something like:adonix/src/services/registration/registration-router.ts
Lines 66 to 126 in 8c8a9f3