import {DeepPartial,IActionsCreator,IQuery,IQueryResults} from "@onebro/oba-common"; import {AppMaster} from "@onebro/appmaster"; import { FirstlineMessageActions, FirstlineMessage, FirstlineMessageModelMap, FirstlineMessageInstanceMap} from "../types"; const wrapup = async (o:FirstlineMessageInstanceMap) => (await o.msg.save()).json(); const wrapupQ = async (o:IQueryResults) => o; export const firstlineMessageActions:IActionsCreator = async (m,{FirstlineMessage}:FirstlineMessageModelMap) => { const actions:FirstlineMessageActions = { create$:async ({body}) => await Promise.resolve() .then(() => FirstlineMessage._create(body)) .then(async o => await FirstlineMessage._populate(o)) .then(o => wrapup({msg:o})), query$:async ({query}) => await Promise.resolve() .then(async () => await FirstlineMessage._query(new IQuery(query as any))) .then(async o => await wrapupQ(o)), fetch$:async ({params:{id}}) => await Promise.resolve() .then(() => FirstlineMessage._find(id)) .then(o => FirstlineMessage._populate(o)) .then(o => wrapup({msg:o})), update$:async ({params:{id},body:updates}) => await Promise.resolve() .then(() => FirstlineMessage._find(id)) .then(o => FirstlineMessage._populate(o)) .then(o => FirstlineMessage._update(o,updates)) .then(o => wrapup({msg:o})), remove$:async ({params:{id}}) => await Promise.resolve() .then(() => FirstlineMessage._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:FirstlineMessage[] = []; 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:FirstlineMessage[] = []; 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; }; /* const sendsms = getWorker("oba-notifier-send-sms"); createSms$:async ({body}) => await Promise.resolve() .then(() => FirstlineMessage._create(body)) .then(o => FirstlineMessage._populate(o)) .then(o => wrapup({msg:o})) .then(async o => { const msgId = await sendsms?sendsms.add(o):null; return {...o,msgId};}), */