server/database/entities/Relationship.ts

62 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Relationship, User } from "@prisma/client";
2023-09-22 05:18:05 +02:00
import { APIRelationship } from "~types/entities/relationship";
import { client } from "~database/datasource";
2023-09-22 05:18:05 +02:00
/**
* Stores Mastodon API relationships
*/
/**
* Creates a new relationship between two users.
* @param owner The user who owns the relationship.
* @param other The user who is the subject of the relationship.
* @returns The newly created relationship.
*/
export const createNewRelationship = async (
owner: User,
other: User
): Promise<Relationship> => {
return await client.relationship.create({
data: {
ownerId: owner.id,
subjectId: other.id,
languages: [],
following: false,
showingReblogs: false,
notifying: false,
followedBy: false,
blocking: false,
blockedBy: false,
muting: false,
mutingNotifications: false,
requested: false,
domainBlocking: false,
endorsed: false,
note: "",
},
});
};
2023-09-22 05:18:05 +02:00
/**
* Converts the relationship to an API-friendly format.
* @returns The API-friendly relationship.
*/
2023-11-20 03:42:40 +01:00
export const relationshipToAPI = (rel: Relationship): APIRelationship => {
return {
blocked_by: rel.blockedBy,
blocking: rel.blocking,
domain_blocking: rel.domainBlocking,
endorsed: rel.endorsed,
followed_by: rel.followedBy,
following: rel.following,
id: rel.subjectId,
muting: rel.muting,
muting_notifications: rel.mutingNotifications,
notifying: rel.notifying,
requested: rel.requested,
showing_reblogs: rel.showingReblogs,
languages: rel.languages,
note: rel.note,
};
};