slate/pages/api/slates/get-serialized.js
2020-09-03 21:42:50 -07:00

29 lines
753 B
JavaScript

import * as Data from "~/node_common/data";
import * as Serializers from "~/node_common/serializers";
import * as Strings from "~/common/strings";
export default async (req, res) => {
let slate = await Data.getSlateById({ id: req.body.data.id });
if (!slate || slate.error) {
return res.status(404).send({
decorator: "SLATE_NOT_FOUND",
error: true,
});
}
slate = Serializers.slate(slate);
let user = await Data.getUserById({ id: slate.data.ownerId });
if (!user || user.error) {
return res.status(200).send({
decorator: "SLATE_OWNER_NOT_FOUND",
data: slate,
});
}
slate.user = Serializers.user(user);
return res.status(200).send({
decorator: "SERIALIZED_SLATE",
data: slate,
});
};