add breakpoints rest

This commit is contained in:
Oleg Isonen committed 2022-05-07 15:20:45 +02:00
1 parent 1b0ea2adf9
commit 1388f7be67
2 files changed
+28 -1

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import { type LoaderFunction } from "remix";
import type { Breakpoint } from "@webstudio-is/sdk";
import * as db from "~/shared/db";
export type ErrorData = {
errors: string;
};
export const loader: LoaderFunction = async ({
params,
}): Promise<Array<Breakpoint> | ErrorData> => {
try {
const data = await db.breakpoints.load(params.projectId);
return data?.values || [];
} catch (error) {
if (error instanceof Error) {
return {
errors: error.message,
};
}
}
return { errors: "Unexpected error" };
};
+5 -1
View File
@@ -8,7 +8,11 @@ import ObjectId from "bson-objectid";
import { applyPatches, type Patch } from "immer";
import { prisma } from "./prisma.server";
export const load = async (projectId: Project["id"]) => {
export const load = async (projectId?: Project["id"]) => {
if (typeof projectId !== "string") {
throw new Error("Project ID required");
}
return await prisma.breakpoints.findUnique({
where: { projectId },
});