{"version":3,"sources":["webpack:///./node_modules/@abaco/gab-module/src/modules/gab-module/api/GabApi.ts"],"names":["GabApi","http","this","get","data","id","body","post","delete","license_plate","getRawCalendarByRange","then","elements","headers","bookings","i","length","translateRawGabData","tempBooking","tempHeaders","book_id","h","request_id","records","pkid","pk_cuaa"],"mappings":"2OAgBqBA,E,WAGjB,WAAYC,GAAgB,uBACxBC,KAAKD,KAAOA,E,2GAMT,8GACWC,KAAKD,KAAKE,IAAI,8BADzB,uCACwDC,MADxD,gD,4IAQA,uHAAmBC,EAAnB,+BAAwB,GAAxB,SACWH,KAAKD,KAAKE,IAAI,uBAAyBE,GADlD,uCACuDD,MADvD,gD,4IAQA,WAAmBE,GAAnB,iGACWJ,KAAKD,KAAKM,KAAK,uBAAwBD,GADlD,uCACyDF,MADzD,gD,gJAQA,WAAsBC,GAAtB,0GACIH,KAAKD,KAAKO,OAAO,uBAAyBH,IAD9C,gD,mJASA,WAAyBA,EAAYI,GAArC,0GACIP,KAAKD,KAAKM,KAAK,uBAAyBF,EAAK,gBAAiB,CACjEI,cAAeA,KAFhB,gD,wJAUA,WAA4BJ,GAA5B,0GACIH,KAAKD,KAAKE,IAAI,uBAAyBE,EAAK,wBADhD,gD,sJAUA,WAA4BC,GAA5B,iGACWJ,KAAKD,KAAKM,KAAK,+BAAgCD,GAD1D,uCACiEF,MADjE,gD,mJAQA,WAAyBE,GAAzB,0GAIIJ,KAAKQ,sBAAsBJ,GAC7BK,MAAK,SAACC,GACH,IAAMC,EAAqC,GACrCC,EAAuC,GAC7C,IAAIF,EACA,MAAO,CACHC,UACAC,YAER,IAAI,IAAIC,EAAIH,EAASI,OAAQD,KAAM,CAC/B,MAA0CE,eAAoBL,EAASG,IAAvE,sBAAQG,EAAR,YAAqBC,OAArB,MAAmC,GAAnC,EACAL,EAASI,EAAYE,SAAWF,EAChC,IAAI,IAAIG,EAAIF,EAAYH,OAAQK,KAC5BR,EAAQM,EAAYE,GAAGC,YAAcH,EAAYE,GAEzD,MAAO,CACHR,UACAC,gBArBT,gD,4IA8BA,WAAkBT,GAAlB,0GACIH,KAAKD,KAAKE,IAAI,wCAA0CE,GAC1DM,MAAK,YAEF,IAF6C,QAAxCP,YAAwC,MAAjC,GAAiC,EACvCmB,EAAuC,GACrCR,EAAIX,EAAKY,OAAQD,KACrBQ,EAAQnB,EAAKW,GAAGS,MAAQpB,EAAKW,GACjC,OAAOQ,MANZ,gD,gJAaA,uHACIrB,KAAKD,KAAKE,IAAI,qCAChBQ,MAAK,YAEF,IAFiD,QAA5CP,YAA4C,MAArC,GAAqC,EAC3CmB,EAA2C,GACzCR,EAAIX,EAAKY,OAAQD,KACrBQ,EAAQnB,EAAKW,GAAGU,SAAWrB,EAAKW,GACpC,OAAOQ,MANZ,gD","file":"js/chunk-2d2297f5.e91b7c87.js","sourcesContent":["import type { HTTPClient } from '@abaco/web-common/src/HTTP';\nimport {\n translateRawGabData,\n} from \"../utilities/helpers\";\nimport type {\n GabDictionary,\n GabHeader,\n GabHeaderRaw,\n GabBooking,\n GabBookingRaw,\n PremiseItem,\n DestinationItem,\n AddGabHeaderRequest,\n GetCalendarByRangeRequest,\n} from '../models/GabModule';\n\nexport default class GabApi {\n private http: HTTPClient;\n\n constructor(http: HTTPClient) {\n this.http = http;\n }\n\n /**\n *\n */\n public async getGabCodes(): Promise {\n return (await this.http.get(\"/gab-api/api/v1/code/codes\")).data;\n }\n\n /**\n * Get GAB element by id\n * @param id\n */\n public async getGabHeader(id = \"\"): Promise {\n return (await this.http.get(\"/gab-api/api/v1/gab/\" + id)).data;\n }\n\n /**\n * Add GAB element (GabRequest + GabBooking)\n * @param body\n */\n public async addGabHeader(body: AddGabHeaderRequest): Promise {\n return (await this.http.post(\"/gab-api/api/v1/gab/\", body)).data;\n }\n\n /**\n *\n * @param id\n */\n public async deleteGabHeader(id: number) {\n return this.http.delete(\"/gab-api/api/v1/gab/\" + id);\n }\n\n /**\n *\n * @param id\n * @param license_plate\n */\n public async editPlateGabHeader(id: number, license_plate: string) {\n return this.http.post(\"/gab-api/api/v1/gab/\" + id + \"/licensePlate\", {\n license_plate: license_plate\n });\n }\n\n /**\n *\n * @param id\n */\n public async notDeliveredGabHeader(id: number) {\n return this.http.get(\"/gab-api/api/v1/gab/\" + id + \"/markAsNotDelivered\");\n }\n\n /**\n * Get calendar of GabBookings in the requested range.\n * Days without bookings will be omitted.\n *\n * @param body\n */\n public async getRawCalendarByRange(body: GetCalendarByRangeRequest): Promise {\n return (await this.http.post(\"/gab-api/api/v1/gab/calendar\", body)).data;\n }\n\n /**\n * getRawCalendarByRange but with refined data\n * @param body\n */\n public async getCalendarByRange(body: GetCalendarByRangeRequest): Promise<{\n headers: Record;\n bookings: Record;\n }> {\n return this.getRawCalendarByRange(body)\n .then((elements: GabBookingRaw[] | null) => {\n const headers: Record = {};\n const bookings: Record = {};\n if(!elements)\n return {\n headers,\n bookings,\n };\n for(let i = elements.length; i--; ){\n const [ tempBooking, tempHeaders = [] ] = translateRawGabData(elements[i]);\n bookings[tempBooking.book_id] = tempBooking;\n for(let h = tempHeaders.length; h--; )\n headers[tempHeaders[h].request_id] = tempHeaders[h];\n }\n return {\n headers,\n bookings,\n };\n });\n }\n\n /**\n * List of premises (stables) of farm\n * @param id\n */\n public async getPremises(id: number): Promise> {\n return this.http.get(\"/gab-api/api/v1/code/premises?farmId=\" + id)\n .then(({ data = [] }: { data: PremiseItem[] }) => {\n const records: Record = {};\n for(let i = data.length; i--; )\n records[data[i].pkid] = data[i];\n return records;\n });\n }\n\n /**\n * List of possible destinations (companies)\n */\n public async getDestinations(): Promise> {\n return this.http.get(\"/gab-api/api/v1/code/destinations\")\n .then(({ data = [] }: { data: DestinationItem[] }) => {\n const records: Record = {};\n for(let i = data.length; i--; )\n records[data[i].pk_cuaa] = data[i];\n return records;\n });\n }\n}\n"],"sourceRoot":""}