Skip to content

Commit 2782446

Browse files
author
Jason Diaz Jimenez
committed
chore: notiffications
1 parent 8217c86 commit 2782446

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

src/routes/v1/Auth/controllers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ export const whoami = async (request: FastifyRequest, reply: FastifyReply) => {
281281
where: { id: user.id },
282282
relations: {
283283
user: {
284-
characters: true
284+
characters: true,
285+
notifications: true,
285286
}
286287
}
287288
})

src/routes/v1/Auth/schemas.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,20 @@ export const WHOAMI_SCHEMA: FastifySchema = {
251251
avatarURL: { type: "string", nullable: true }
252252
}
253253
}
254-
}
254+
},
255+
notifications: {
256+
type: "array",
257+
properties: {
258+
id: { type: "string", format: "uuid" },
259+
content: { type: "string" },
260+
read: { type: "boolean" },
261+
user: { type: "string", format: "uuid" },
262+
sender: { type: "string", format: "uuid", nullable: true },
263+
artwork: { type: "string", format: "uuid", nullable: true },
264+
comment: { type: "string", format: "uuid", nullable: true },
265+
createdAt: { type: "string", format: "date-time" }
266+
}
267+
},
255268
}
256269
},
257270
401: {

src/routes/v1/Profile/controllers.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { FastifyReply, FastifyRequest } from "fastify"
22
import { Character, Image, User } from "../../../models"
3-
import { Comment, Comment as Comments } from "../../../models/Comments"
3+
import { Comment } from "../../../models"
44
import { uploadToS3 } from "../../../utils"
55
import { DataSource, ILike, IsNull } from "typeorm"
6-
import { sendMassNotification } from "../../../utils/notification"
6+
import { sendMassNotification, sendNotification } from "../../../utils/notification"
77
import { CommissionStatus, Role } from "../../../models/Users"
88

99
export const me = async (request: FastifyRequest, reply: FastifyReply) => {
@@ -88,6 +88,7 @@ export const getProfile = async (request: FastifyRequest, reply: FastifyReply) =
8888
handle: handle
8989
},
9090
relations: {
91+
notifications: true,
9192
folders: {
9293
characters: true,
9394
artworks: true,
@@ -165,7 +166,7 @@ export const commentProfile = async (request: FastifyRequest, reply: FastifyRepl
165166
}
166167
}
167168

168-
const comment = await request.server.db.getRepository(Comments).save({
169+
const comment = await request.server.db.getRepository(Comment).save({
169170
content: content,
170171
author: author,
171172
user: profile,
@@ -176,6 +177,8 @@ export const commentProfile = async (request: FastifyRequest, reply: FastifyRepl
176177
return reply.code(500).send({ error: "Error commenting" })
177178
}
178179

180+
await sendNotification(request.server.db, profile, "New comment on your profile", author, undefined, comment)
181+
179182
return reply.code(200).send({ message: "Commented" })
180183
}
181184

@@ -401,7 +404,7 @@ export const getArtistsWithOpenCommissions = async (request: FastifyRequest, rep
401404
}
402405

403406
const recursivelyGetReplies = async (commentId: string, db: DataSource) => {
404-
const replies = await db.getRepository(Comments).find({
407+
const replies = await db.getRepository(Comment).find({
405408
where: { parentComment: { id: commentId } },
406409
relations: {
407410
author: true,

src/routes/v1/Profile/schemas.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ export const GET_PROFILE_SCHEMA: FastifySchema = {
9191
},
9292
pronouns: { type: "string" },
9393
nationality: { type: "string" },
94+
notifications: {
95+
type: "array",
96+
properties: {
97+
id: { type: "string", format: "uuid" },
98+
content: { type: "string" },
99+
read: { type: "boolean" },
100+
user: { type: "string", format: "uuid" },
101+
sender: { type: "string", format: "uuid", nullable: true },
102+
artwork: { type: "string", format: "uuid", nullable: true },
103+
comment: { type: "string", format: "uuid", nullable: true },
104+
createdAt: { type: "string", format: "date-time" }
105+
}
106+
},
94107
birthday: { type: "string", format: "date-time" }
95108
},
96109
404: {

src/utils/notification.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DataSource } from "typeorm"
22
import { type Artwork, type User } from "../models"
3-
import type { Comment } from "../models/Comments"
4-
import { Notification } from "../models/Notifications"
3+
import type Comment from "../models/Comments"
4+
import Notification from "../models/Notifications"
55

66
export const sendNotification = async (client: DataSource, user: User, content: string, sender?: User, artwork?: Artwork, comment?: Comment) => {
77
const notification = await client.getRepository(Notification).save({

0 commit comments

Comments
 (0)