balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

Templates.js (2179B)


      1 import { createTemplatesFilterFormula } from '../util/airtable'
      2 import { Axios as api } from './axios'
      3 import { templates as config } from '../config'
      4 
      5 let count = 0
      6 
      7 export const Templates = {
      8     async get(searchParams, options = {}) {
      9         count++
     10         const templates = await api.post('templates', {
     11             filterByFormula: createTemplatesFilterFormula(searchParams),
     12             pageSize: options?.pageSize ?? config.templatesPerRequest,
     13             categories: searchParams.taxonomies,
     14             search: searchParams.search,
     15             type: searchParams.type,
     16             offset: options.offset ?? '',
     17             initial: count === 1,
     18             request_count: count,
     19         })
     20         return templates
     21     },
     22     related(
     23         template, queryType, wantedType,
     24     ) {
     25         return api.post('related', {
     26             pageSize: 4,
     27             query_type: queryType,
     28             wanted_type: wantedType,
     29             categories: template?.fields?.tax_categories,
     30             pattern_types: template?.fields?.tax_pattern_types,
     31             style: template?.fields?.tax_style,
     32             type: template?.fields?.type,
     33             template_id: template?.id,
     34         })
     35     },
     36 
     37     // TODO: Refactor this later to combine the following three
     38     maybeImport(template) {
     39         return api.post(`templates/${template.id}`, {
     40             template_id: template.id,
     41             maybe_import: true,
     42             type: template.fields.type,
     43             pageSize: config.templatesPerRequest,
     44             template_name: template.fields?.title,
     45         })
     46     },
     47     single(template) {
     48         return api.post(`templates/${template.id}`, {
     49             template_id: template.id,
     50             single: true,
     51             type: template.fields.type,
     52             pageSize: config.templatesPerRequest,
     53             template_name: template.fields?.title,
     54         })
     55     },
     56     import(template) {
     57         return api.post(`templates/${template.id}`, {
     58             template_id: template.id,
     59             imported: true,
     60             type: template.fields.type,
     61             pageSize: config.templatesPerRequest,
     62             template_name: template.fields?.title,
     63         })
     64     },
     65 }