summaryrefslogtreecommitdiff
path: root/apps/web/src/services/storage/migrations/transformers/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/services/storage/migrations/transformers/utils.ts')
-rw-r--r--apps/web/src/services/storage/migrations/transformers/utils.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/apps/web/src/services/storage/migrations/transformers/utils.ts b/apps/web/src/services/storage/migrations/transformers/utils.ts
new file mode 100644
index 00000000..108489bf
--- /dev/null
+++ b/apps/web/src/services/storage/migrations/transformers/utils.ts
@@ -0,0 +1,28 @@
+import type { ProjectRecord } from "./types";
+
+export function isRecord(value: unknown): value is ProjectRecord {
+ return typeof value === "object" && value !== null;
+}
+
+export function getProjectId({
+ project,
+}: {
+ project: ProjectRecord;
+}): string | null {
+ const idValue = project.id;
+ if (typeof idValue === "string" && idValue.length > 0) {
+ return idValue;
+ }
+
+ const metadataValue = project.metadata;
+ if (!isRecord(metadataValue)) {
+ return null;
+ }
+
+ const metadataId = metadataValue.id;
+ if (typeof metadataId === "string" && metadataId.length > 0) {
+ return metadataId;
+ }
+
+ return null;
+}