Skip to content

Commit cc23248

Browse files
Issue#2494: disassociate device on delete (#125)
* disassociate device on delete * refactor: fixing the promise to disassociate each device Id from all certificates it is bound to * add promise.all on disassociateCertificates Co-authored-by: luisfelipefurlan <[email protected]>
1 parent 954e502 commit cc23248

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/operations/device/mutation.deleteDevices.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
import LOG from '../../utils/Log.js';
2-
import * as service from '../../services/service.device.js';
1+
import LOG from "../../utils/Log.js";
2+
import * as service from "../../services/service.device.js";
3+
import * as securityService from "../../services/service.security";
34

45
const deleteDevices = async (_, { deviceIds }, { token }) => {
56
try {
6-
const promises = deviceIds.map(
7-
async (deviceId) => {
8-
await service.deleteDevice(token, deviceId);
9-
},
10-
);
11-
await Promise.all(promises);
12-
return 'ok';
7+
const disassociateCertificatesPromise = deviceIds.map(async (deviceId) => {
8+
const { data: certificateData } = await securityService
9+
.getAllCertificates(
10+
token,
11+
undefined,
12+
undefined,
13+
deviceId,
14+
);
15+
const { certificates } = certificateData;
16+
const disassociateLinkedCertificates = certificates.map(async (certificate) => {
17+
await securityService.disassociateCertificate(token, certificate.fingerprint);
18+
});
19+
await Promise.all(disassociateLinkedCertificates);
20+
});
21+
const deleteDevicesPromise = deviceIds.map(async (deviceId) => {
22+
await service.deleteDevice(token, deviceId);
23+
});
24+
await Promise.all(disassociateCertificatesPromise);
25+
await Promise.all(deleteDevicesPromise);
26+
return "ok";
1327
} catch (error) {
1428
LOG.error(error.stack || error);
1529
throw error;

0 commit comments

Comments
 (0)