Skip to content

Commit a31723d

Browse files
Merge pull request #383 from bakaphp/feat/branch-photo
feat: upload photo to company branch
2 parents 7ac5770 + a18824c commit a31723d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.27.5",
2+
"version": "0.28.0",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",

src/modules/filesystem/index.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,48 @@ export class FileSystem {
269269
}
270270
return response.data.data.updateCompanyPhotoProfile as CompanyInterface;
271271
}
272+
273+
public async updateCompanyBranchPhotoProfile(
274+
data: File,
275+
branch_id: string
276+
): Promise<any> {
277+
if (!this.options || !this.axiosClient) {
278+
throw new Error('FileSystem module not initialized');
279+
}
280+
281+
const query = `
282+
id
283+
uuid
284+
name
285+
custom_fields(orderBy: [{ column: UPDATED_AT, order: DESC }]) {
286+
data {
287+
name
288+
value
289+
}
290+
}
291+
photo {
292+
url
293+
}
294+
`;
295+
296+
const operations = {
297+
query: `mutation ($file: Upload!) {
298+
updateCompanyPhotoProfile(file: $file, id: "${branch_id}") { ${query} }
299+
}`,
300+
variables: { file: null },
301+
};
302+
303+
const formData = new FormData();
304+
formData.append('operations', JSON.stringify(operations));
305+
formData.append('map', JSON.stringify({ '0': ['variables.file'] }));
306+
formData.append('0', data, data.name);
307+
308+
const response = await this.axiosClient.post('', formData);
309+
310+
if (response.data.errors) {
311+
throw new Error(response.data.errors[0].message);
312+
}
313+
314+
return response.data;
315+
}
272316
}

0 commit comments

Comments
 (0)