slate/node_common/serializers.js

111 lines
2.9 KiB
JavaScript
Raw Normal View History

//NOTE(martina): when you add any new variable to the user, file, or slate objects, add it in these structures
//add it to sanitize___ if it should be sent to the front end
//add it to clean____ if it should be saved to the database
//NOTE(martina): these functions are to remove sensitive information before sending the data to the front end
//only variables listed here will be sent to the front end
export const sanitizeUser = (entity) => {
return {
id: entity.id,
username: entity.username,
slates: entity.slates, //NOTE(martina): this is not in the database. It is added after
library: entity.library, //NOTE(martina): this is not in the database. It is added after
2021-08-29 03:29:17 +03:00
name: entity.name,
2021-08-29 04:36:48 +03:00
body: entity.body,
photo: entity.photo,
followerCount: entity.followerCount,
slateCount: entity.slateCount,
};
};
export const sanitizeSlate = (entity) => {
return {
id: entity.id,
slatename: entity.slatename,
2021-08-29 03:29:17 +03:00
name: entity.name,
ownerId: entity.ownerId,
isPublic: entity.isPublic,
objects: entity.objects,
owner: entity.owner,
user: entity.user, //NOTE(martina): this is not in the database. It is added after
2021-08-29 04:36:48 +03:00
body: entity.body,
preview: entity.preview,
fileCount: entity.fileCount,
subscriberCount: entity.subscriberCount,
};
};
export const sanitizeFile = (entity) => {
2020-08-31 21:10:42 +03:00
return {
id: entity.id,
cid: entity.cid,
ownerId: entity.ownerId,
isPublic: entity.isPublic,
filename: entity.filename,
2021-08-29 03:29:17 +03:00
name: entity.name,
createdAt: entity.createdAt,
2021-08-29 04:36:48 +03:00
body: entity.body,
2021-08-31 00:20:24 +03:00
size: entity.size,
2021-08-31 01:03:45 +03:00
type: entity.type,
blurhash: entity.blurhash,
source: entity.source,
author: entity.author,
coverImage: entity.coverImage,
linkName: entity.linkName,
linkBody: entity.linkBody,
linkSource: entity.linkSource,
linkAuthor: entity.linkAuthor,
linkDomain: entity.linkDomain,
linkImage: entity.linkImage,
linkFavicon: entity.linkFavicon,
linkHtml: entity.linkHtml,
linkIFrameAllowed: entity.linkIFrameAllowed,
2021-09-01 03:27:41 +03:00
tags: entity.tags,
data: {
unity: entity.data?.unity, //NOTE(martina): newly added
},
downloadCount: entity.downloadCount,
saveCount: entity.saveCount,
2021-07-07 23:50:57 +03:00
isLink: entity.isLink,
url: entity.url,
2020-08-31 21:10:42 +03:00
};
};
2021-07-07 23:50:57 +03:00
//NOTE(martina): list of the properties of the tables that should be returned by db queries
export const slateProperties = [
"slates.id",
"slates.slatename",
2021-08-29 03:29:17 +03:00
"slates.name",
2021-08-29 04:36:48 +03:00
"slates.body",
2021-07-07 23:50:57 +03:00
"slates.ownerId",
"slates.isPublic",
"slates.subscriberCount",
"slates.fileCount",
];
export const userProperties = [
"users.id",
"users.username",
2021-08-29 03:29:17 +03:00
"users.name",
2021-08-29 04:36:48 +03:00
"users.body",
2021-07-07 23:50:57 +03:00
"users.slateCount",
"users.followerCount",
];
export const fileProperties = [
"files.id",
"files.ownerId",
"files.cid",
"files.isPublic",
"files.filename",
2021-08-29 03:29:17 +03:00
"files.name",
2021-08-29 04:36:48 +03:00
"files.body",
2021-07-07 23:50:57 +03:00
"files.data",
"files.createdAt",
"files.downloadCount",
"files.saveCount",
"files.isLink",
"files.url",
];