synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
49 lines (48 loc) • 1.46 kB
JavaScript
import { useCreateEntity as d, useGetEntityLookupQueryOptions as l, useGetEntityQueryOptions as m } from "../../../synapse-queries/entity/useEntity.js";
import { useQueryClient as f, useMutation as E } from "@tanstack/react-query";
import { convertToEntityType as g, entityTypeToFriendlyName as h } from "../../functions/EntityTypeUtils.js";
function C() {
const { mutateAsync: i } = d(), r = f(), s = l(), y = m();
return E({
mutationFn: async (a) => {
const { rootContainerId: c, path: u } = a;
let t = c;
for (const o of u) {
const n = await r.fetchQuery(
s({
parentId: t,
entityName: o
})
);
if (n) {
const e = await r.fetchQuery(
y(n)
);
if (e.concreteType != "org.sagebionetworks.repo.model.Folder") {
const p = g(
e.concreteType
);
throw new Error(
`A(n) ${h(
p
)} named "${o}" already exists in this location (${t}). A folder could not be created.`
);
}
t = n;
} else {
const { id: e } = await i({
concreteType: "org.sagebionetworks.repo.model.Folder",
name: o,
parentId: t
});
t = e;
}
}
return t;
}
});
}
export {
C as useCreateFolderPath
};
//# sourceMappingURL=useCreateFolderPath.js.map