Skip to content

Commit

Permalink
Merge pull request #167 from hemedani/main
Browse files Browse the repository at this point in the history
🐛 fixed validation steps and body pass flow
  • Loading branch information
hemedani authored Jun 5, 2024
2 parents 2d1c27c + def11db commit 86ff7a3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/utils/serveLesan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { addCorsObj } from "../server/cors.ts";
import { parsBody, TLesanBody } from "./mod.ts";

const runPreHooks = async (preActs: Function[]) => {
for (const func of preActs) {
for await (const func of preActs) {
await func();
}
};
Expand Down Expand Up @@ -36,15 +36,18 @@ export const lesanFns = (actsObj: Services) => {
);

act.preValidation && await runPreHooks(act.preValidation);
body = contextFns.getContextModel().body!;

act.validationRunType === "create"
? create(body.details, act.validator)
: assert(body.details, act.validator);
body = contextFns.getContextModel().body!;
if (act.validationRunType === "create") {
const createdDetails = await create(body.details, act.validator);
body = {
...body,
details: createdDetails,
};
} else {
assert(body.details, act.validator);
}

act.preAct && await runPreHooks(act.preAct);
body = contextFns.getContextModel().body!;

return await act.fn(body);
};
Expand Down Expand Up @@ -183,8 +186,10 @@ export const lesanFns = (actsObj: Services) => {
return await checkServices(req, port);
};

const RS = await response();

return new Response(
JSON.stringify({ body: await response(), success: true }),
JSON.stringify({ body: RS, success: true }),
{
headers: {
...addCorsObj(cors, req.headers.get("origin")),
Expand Down

0 comments on commit 86ff7a3

Please sign in to comment.