Skip to content

Confusing Endpoints #331

Description

@AydanPirani

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);
},
);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions