Skip to content

Commit

Permalink
feat: replace empty response body with 204 status code
Browse files Browse the repository at this point in the history
  • Loading branch information
fruneen committed Jan 29, 2024
1 parent 77c8146 commit 715c644
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ValidatedData extends z.infer<typeof schema> {
async function validator(ctx: AppKoaContext<ValidatedData>, next: Next) {
const user = await userService.findOne({ email: ctx.validatedData.email });

if (!user) return ctx.body = {};
if (!user) return ctx.status = 204;

ctx.validatedData.user = user;
await next();
Expand Down Expand Up @@ -53,7 +53,7 @@ async function handler(ctx: AppKoaContext<ValidatedData>) {
},
});

ctx.body = {};
ctx.status = 204;
}

export default (router: AppRouter) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function validator(ctx: AppKoaContext<ValidatedData>, next: Next) {

const user = await userService.findOne({ email });

if (!user) return ctx.body = {};
if (!user) return ctx.status = 204;

ctx.validatedData.user = user;
await next();
Expand All @@ -50,7 +50,7 @@ async function handler(ctx: AppKoaContext<ValidatedData>) {
}),
]);

ctx.body = {};
ctx.status = 204;
}

export default (router: AppRouter) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function validator(ctx: AppKoaContext<ValidatedData>, next: Next) {

const user = await userService.findOne({ resetPasswordToken: token });

if (!user) return ctx.body = {};
if (!user) return ctx.status = 204;

ctx.validatedData.user = user;
await next();
Expand All @@ -38,7 +38,7 @@ async function handler(ctx: AppKoaContext<ValidatedData>) {
resetPasswordToken: null,
}));

ctx.body = {};
ctx.status = 204;
}

export default (router: AppRouter) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { authService } from 'services';
const handler = async (ctx: AppKoaContext) => {
await authService.unsetTokens(ctx);

ctx.body = {};
ctx.status = 204;
};

export default (router: AppRouter) => {
Expand Down
7 changes: 6 additions & 1 deletion template/apps/api/src/resources/account/actions/sign-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ async function handler(ctx: AppKoaContext<ValidatedData>) {
},
});

ctx.body = config.IS_DEV ? { signupToken } : {};
if (config.IS_DEV) {
ctx.body = { signupToken };
return;
}

ctx.status = 204;
}

export default (router: AppRouter) => {
Expand Down
2 changes: 1 addition & 1 deletion template/apps/api/src/resources/user/actions/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function validator(ctx: AppKoaContext<ValidatedData, Request>, next: Next)
async function handler(ctx: AppKoaContext<ValidatedData, Request>) {
await userService.deleteSoft({ _id: ctx.request.params.id });

ctx.body = {};
ctx.status = 204;
}

export default (router: AppRouter) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const adminAuth = (ctx: AppKoaContext, next: Next) => {
}

ctx.status = 401;
ctx.body = {};

return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const auth = (ctx: AppKoaContext, next: Next) => {
}

ctx.status = 401;
ctx.body = {};

return null;
};
Expand Down

0 comments on commit 715c644

Please sign in to comment.