Skip to content

Commit

Permalink
Added plan items
Browse files Browse the repository at this point in the history
  • Loading branch information
jzongker committed Feb 8, 2025
1 parent 213f644 commit 93ef0eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/controllers/PlanItemController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { controller, httpPost, httpGet, interfaces, requestParam, httpDelete } from "inversify-express-utils";
import express from "express";
import { DoingBaseController } from "./DoingBaseController"
import { PlanItem, Position, Time } from "../models"

import { PlanItem } from "../models"

@controller("/planItems")
export class PlanItemController extends DoingBaseController {
Expand All @@ -26,7 +25,8 @@ export class PlanItemController extends DoingBaseController {
@httpGet("/plan/:planId")
public async getByPlan(@requestParam("planId") planId: string, req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
return await this.repositories.planItem.loadForPlan(au.churchId, planId);
const result = await this.repositories.planItem.loadForPlan(au.churchId, planId);
return this.buildTree(result, null);
});
}

Expand All @@ -51,4 +51,16 @@ export class PlanItemController extends DoingBaseController {
});
}

private buildTree(planItems: PlanItem[], parentId: string): PlanItem[] {
const result: PlanItem[] = [];
planItems.forEach(pi => {
if (pi.parentId === parentId) {
pi.children = this.buildTree(planItems, pi.id);
result.push(pi);
}
});
return result;
}


}
4 changes: 3 additions & 1 deletion src/models/PlanItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ export class PlanItem {
public relatedId?: string;
public label?: string;
public description?: string;
public seconds?: string;
public seconds?: number;

public children?: PlanItem[];
}

0 comments on commit 93ef0eb

Please sign in to comment.