Skip to content

Commit

Permalink
Made planItems sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
jzongker committed Feb 8, 2025
1 parent 93ef0eb commit cca6249
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/controllers/PlanItemController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ export class PlanItemController extends DoingBaseController {
});
}

@httpPost("/sort")
public async sort(req: express.Request<{}, {}, PlanItem>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
await this.repositories.planItem.save(req.body);

const items = await this.repositories.planItem.loadForPlan(au.churchId, req.body.planId);
const filtered = items.filter((i: PlanItem) => i.parentId === req.body.parentId);
filtered.sort((a: PlanItem, b: PlanItem) => a.sort - b.sort);
for (let i = 0; i < filtered.length; i++) {
filtered[i].sort = i + 1;
await this.repositories.planItem.save(filtered[i]);
}
return [];
});
}

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

0 comments on commit cca6249

Please sign in to comment.