前端项目实战99-数据postgrest.查看详情接口封装

时间:2023-02-12 10:57:47


getOne: (resource: any, params: any) => {
const key: any = Object.keys(params)
const id = params[key[0]];
const primaryKey = getPrimaryKey(resource, primaryKeys);

const query = getQuery(primaryKey, id, resource);

//转换id
const url = `${PostgrestUrl}/${resource}?${query.replace("id", key[0])}&is_delete=eq.0`;

return httpClient(url, {
headers: new Headers({}),
}).then(({ json }) => ({
data: dataWithId(json, primaryKey),
})).catch((err) => {
return err
})
},