async shareEntity()

in src/lib/service/custos-service/custos-service-sharing.js [102:136]


    async shareEntity({clientId, entityId, permissionTypeId, groupIds = [], usernames = [], sharedBy}) {
        const axiosInstance = await this.custosService.axiosInstance;

        let promises = [];

        promises.concat(groupIds.map(groupId => {
            return axiosInstance.post(
                `${CustosService.ENDPOINTS.SHARING}/groups/share`,
                {
                    "client_id": clientId,
                    "entity": {"id": entityId},
                    "permission_type": {"id": permissionTypeId},
                    "owner_id": [groupId],
                    "cascade": true,
                    "shared_by": sharedBy
                }
            );
        }));

        promises.concat(usernames.map(username => {
            return axiosInstance.post(
                `${CustosService.ENDPOINTS.SHARING}/users/share`,
                {
                    "client_id": clientId,
                    "entity": {"id": entityId},
                    "permission_type": {"id": permissionTypeId},
                    "owner_id": [username],
                    "cascade": true,
                    "shared_by": sharedBy
                }
            );
        }));

        await Promise.all(promises);
    }