2021-03-07 23:53:54 +03:00
|
|
|
import * as Utilities from "~/node_common/utilities";
|
|
|
|
import * as Data from "~/node_common/data";
|
|
|
|
import * as Strings from "~/common/strings";
|
2021-07-14 01:52:21 +03:00
|
|
|
import * as RequestUtilities from "~/node_common/request-utilities";
|
2021-11-12 01:10:53 +03:00
|
|
|
import * as Conversions from "~/common/conversions";
|
2021-03-07 23:53:54 +03:00
|
|
|
|
|
|
|
export default async (req, res) => {
|
2021-07-14 01:52:21 +03:00
|
|
|
const userInfo = await RequestUtilities.checkAuthorizationExternal(req, res);
|
|
|
|
if (!userInfo) return;
|
|
|
|
const { id, key, user } = userInfo;
|
2021-03-07 23:53:54 +03:00
|
|
|
|
2021-11-12 04:44:14 +03:00
|
|
|
let reformattedUser = Conversions.convertToV3User(user);
|
|
|
|
|
2021-11-12 01:10:53 +03:00
|
|
|
let slates = await Data.getSlatesByUserId({
|
|
|
|
ownerId: id,
|
2021-03-07 23:53:54 +03:00
|
|
|
includeFiles: true,
|
|
|
|
});
|
|
|
|
|
2021-11-12 01:10:53 +03:00
|
|
|
if (!slates) {
|
2021-03-07 23:53:54 +03:00
|
|
|
return res.status(404).send({
|
2021-11-12 01:10:53 +03:00
|
|
|
decorator: "COULD_NOT_FETCH_COLLECTIONS",
|
2021-03-07 23:53:54 +03:00
|
|
|
error: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-12 01:10:53 +03:00
|
|
|
if (slates.error) {
|
2021-03-07 23:53:54 +03:00
|
|
|
return res.status(500).send({
|
2021-11-12 01:10:53 +03:00
|
|
|
decorator: "COULD_NOT_FETCH_COLLECTIONS",
|
2021-03-07 23:53:54 +03:00
|
|
|
error: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-12 04:44:14 +03:00
|
|
|
return res.status(200).send({ decorator: "GET", user: reformattedUser, collections: slates });
|
2021-03-07 23:53:54 +03:00
|
|
|
};
|