import {DeepPartial,IActionsCreator,IQuery,IQueryResults} from "@onebro/oba-common"; import {AppMaster} from "@onebro/appmaster"; import { FinavigatorAppointmentActions, FinavigatorAppointment, FinavigatorAppointmentModelMap, FinavigatorAppointmentInstanceMap} from "../types"; const wrapup = async (o:FinavigatorAppointmentInstanceMap) => (await o.appt.save()).json(); const wrapupQ = async (o:IQueryResults) => o; export const finavigatorAppointmentActions:IActionsCreator = async (m,{FinavigatorAppointment}:FinavigatorAppointmentModelMap) => { const actions:FinavigatorAppointmentActions = { create$:async ({body}) => await Promise.resolve() .then(() => FinavigatorAppointment._create(body)) .then(async o => await FinavigatorAppointment._populate(o)) .then(o => wrapup({appt:o})), query$:async ({query}) => await Promise.resolve() .then(async () => await FinavigatorAppointment._query(new IQuery(query as any))) .then(async o => await wrapupQ(o)), fetch$:async ({params:{id}}) => await Promise.resolve() .then(() => FinavigatorAppointment._find(id)) .then(o => FinavigatorAppointment._populate(o)) .then(o => wrapup({appt:o})), update$:async ({params:{id},body:updates}) => await Promise.resolve() .then(() => FinavigatorAppointment._find(id)) .then(o => FinavigatorAppointment._populate(o)) .then(o => FinavigatorAppointment._update(o,updates)) .then(o => wrapup({appt:o})), remove$:async ({params:{id}}) => await Promise.resolve() .then(() => FinavigatorAppointment._find(id)) .then(o => o.remove()) .then(() => ({removed:id})), updateMany$:async ({body:{ids,updates}}:{body:{ids:string[],updates:DeepPartial}}) => await Promise.resolve() .then(async () => { if(ids.length){ const arr:FinavigatorAppointment[] = []; for(let i = 0,l = ids.length;i { for(let i = 0,l = ids.length;i ({updated:n} as any)), removeMany$:async ({body:{ids}}:{body:{ids:string[]}}) => await Promise.resolve() .then(async () => { if(ids.length){ const arr:FinavigatorAppointment[] = []; for(let i = 0,l = ids.length;i { for(let i = 0,l = o.length;i ({removed:n} as any)), search$:async ({body}) => await Promise.resolve({results:[]}), }; return actions; };