Skip to content

Commit

Permalink
Added public footer route
Browse files Browse the repository at this point in the history
  • Loading branch information
jzongker committed Dec 31, 2024
1 parent 29ba5c5 commit 262bd92
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/controllers/BlockController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ContentBaseController } from "./ContentBaseController"
import { Block, Element, Section } from "../models"
import { Permissions } from "../helpers";
import { TreeHelper } from "../helpers/TreeHelper";
import { ArrayHelper } from "@churchapps/apihelper";

@controller("/blocks")
export class BlockController extends ContentBaseController {
Expand Down Expand Up @@ -53,6 +54,31 @@ export class BlockController extends ContentBaseController {
});
}

@httpGet("/public/footer/:churchId")
public async loadFooter(@requestParam("churchId") churchId: string, req: express.Request, res: express.Response): Promise<any> {
return this.actionWrapperAnon(req, res, async () => {
const footerBlocks = await this.repositories.block.loadByBlockType(churchId, "footerBlock");
const result:Section[] = [];
console.log("Footer Blocks", footerBlocks.length);
if (footerBlocks.length > 0) {
const blockIds: string[] = ArrayHelper.getIds(footerBlocks, "id");
const allBlockSections = await this.repositories.section.loadForBlocks(churchId, blockIds);
const allBlockElements = await this.repositories.element.loadForBlocks(churchId, blockIds);
console.log("All Block Sections", allBlockSections.length);

const footerBlockSections = ArrayHelper.getAll(allBlockSections, "blockId", footerBlocks[0].id);
footerBlockSections.forEach(s => {
s.zone="siteFooter";
const blockElements = ArrayHelper.getAll(allBlockElements, "blockId", footerBlocks[0].id);
const tree = TreeHelper.buildTree([s], blockElements);
result.push(...tree);
});
}
return result;

});
}

@httpPost("/")
public async save(req: express.Request<{}, {}, Block[]>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
Expand Down

0 comments on commit 262bd92

Please sign in to comment.