mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Complete migration to Prisma, all tests passing
This commit is contained in:
parent
dc0ec47543
commit
3884763235
18 changed files with 74 additions and 39 deletions
|
|
@ -52,8 +52,7 @@ export const relationshipToAPI = async (
|
|||
endorsed: rel.endorsed,
|
||||
followed_by: rel.followedBy,
|
||||
following: rel.following,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
id: (rel as any).subject.id,
|
||||
id: rel.subjectId,
|
||||
muting: rel.muting,
|
||||
muting_notifications: rel.mutingNotifications,
|
||||
notifying: rel.notifying,
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ export type StatusWithRelations = Status & {
|
|||
* @returns Whether this status is viewable by the user.
|
||||
*/
|
||||
export const isViewableByUser = (status: Status, user: User | null) => {
|
||||
if (status.authorId === user?.id) return true;
|
||||
if (status.visibility === "public") return true;
|
||||
else if (status.visibility === "unlisted") return true;
|
||||
else if (status.visibility === "private") {
|
||||
|
|
@ -378,7 +379,7 @@ export const createNewStatus = async (data: {
|
|||
});
|
||||
}
|
||||
|
||||
const status = await client.status.create({
|
||||
let status = await client.status.create({
|
||||
data: {
|
||||
authorId: data.account.id,
|
||||
applicationId: data.application?.id,
|
||||
|
|
@ -398,7 +399,9 @@ export const createNewStatus = async (data: {
|
|||
quotingPostId: data.quote?.id,
|
||||
instanceId: data.account.instanceId || undefined,
|
||||
isReblog: false,
|
||||
uri: data.uri || `${config.http.base_url}/statuses/xxx`,
|
||||
uri:
|
||||
data.uri ||
|
||||
`${config.http.base_url}/statuses/FAKE-${crypto.randomUUID()}`,
|
||||
mentions: {
|
||||
connect: mentions.map(mention => {
|
||||
return {
|
||||
|
|
@ -410,7 +413,16 @@ export const createNewStatus = async (data: {
|
|||
include: statusAndUserRelations,
|
||||
});
|
||||
|
||||
if (!data.uri) status.uri = `${config.http.base_url}/statuses/${status.id}`;
|
||||
// Update URI
|
||||
status = await client.status.update({
|
||||
where: {
|
||||
id: status.id,
|
||||
},
|
||||
data: {
|
||||
uri: data.uri || `${config.http.base_url}/statuses/${status.id}`,
|
||||
},
|
||||
include: statusAndUserRelations,
|
||||
});
|
||||
|
||||
return status;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -240,6 +240,15 @@ export const createNewLocalUser = async (data: {
|
|||
},
|
||||
data: {
|
||||
uri: `${config.http.base_url}/users/${user.id}`,
|
||||
endpoints: {
|
||||
disliked: `${config.http.base_url}/users/${user.id}/disliked`,
|
||||
featured: `${config.http.base_url}/users/${user.id}/featured`,
|
||||
liked: `${config.http.base_url}/users/${user.id}/liked`,
|
||||
followers: `${config.http.base_url}/users/${user.id}/followers`,
|
||||
following: `${config.http.base_url}/users/${user.id}/following`,
|
||||
inbox: `${config.http.base_url}/users/${user.id}/inbox`,
|
||||
outbox: `${config.http.base_url}/users/${user.id}/outbox`,
|
||||
},
|
||||
},
|
||||
include: userRelations,
|
||||
});
|
||||
|
|
@ -349,8 +358,7 @@ export const userToAPI = async (
|
|||
url: user.uri,
|
||||
avatar: getAvatarUrl(user, config),
|
||||
header: getHeaderUrl(user, config),
|
||||
// TODO: Add locked
|
||||
locked: false,
|
||||
locked: user.isLocked,
|
||||
created_at: new Date(user.createdAt).toISOString(),
|
||||
followers_count: user.relationshipSubjects.filter(r => r.following)
|
||||
.length,
|
||||
|
|
@ -359,8 +367,7 @@ export const userToAPI = async (
|
|||
emojis: await Promise.all(user.emojis.map(emoji => emojiToAPI(emoji))),
|
||||
// TODO: Add fields
|
||||
fields: [],
|
||||
// TODO: Add bot
|
||||
bot: false,
|
||||
bot: user.isBot,
|
||||
source:
|
||||
isOwnAccount && user.source
|
||||
? (user.source as any as APISource)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue