MCPcopy Create free account
hub / github.com/benwinding/react-admin-import-csv / updateInDataProvider

Function updateInDataProvider

src/uploader.ts:139–191  ·  view source on GitHub ↗
(
  logging: boolean,
  disableUpdateMany: boolean,
  dataProvider: DataProvider,
  resource: string,
  values: any[]
)

Source from the content-addressed store, hash-verified

137}
138
139async function updateInDataProvider(
140 logging: boolean,
141 disableUpdateMany: boolean,
142 dataProvider: DataProvider,
143 resource: string,
144 values: any[]
145) {
146 const ids = values.map((v) => v.id);
147 logger.setEnabled(logging);
148 logger.log("updateInDataProvider", {
149 dataProvider,
150 resource,
151 values,
152 logging,
153 ids,
154 });
155 if (disableUpdateMany) {
156 const items = await updateInDataProviderFallback(dataProvider, resource, values);
157 return items;
158 }
159 const reportItems: ReportItem[] = [];
160 try {
161 const response = await dataProvider.updateManyArray(resource, { ids: ids, data: values });
162 reportItems.push({
163 value: null, success: true, response: response
164 })
165 } catch (error) {
166 const providerMethodNotFoundErrors = [
167 "Unknown dataProvider",
168 "updateMany",
169 ];
170 const shouldTryFallback = doesErrorContainString(error, providerMethodNotFoundErrors);
171 const apiError = !shouldTryFallback;
172 if (apiError) {
173 reportItems.push({
174 value: null, err: error, success: false, response: null
175 })
176 }
177 if (shouldTryFallback) {
178 logger.log(
179 "updateInDataProvider",
180 "updateManyArray not found on data provider (you may need to implement it see: https://github.com/benwinding/react-admin-import-csv#reducing-requests): using fallback instead"
181 );
182 try {
183 const items = await updateInDataProviderFallback(dataProvider, resource, values);
184 reportItems.push(...items);
185 } catch (error) {
186 logger.error("updateInDataProvider", error);
187 }
188 }
189 }
190 return reportItems;
191}
192
193async function updateInDataProviderFallback(
194 dataProvider: DataProvider,

Callers 1

updateFunction · 0.85

Calls 5

doesErrorContainStringFunction · 0.85
setEnabledMethod · 0.80
logMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected