mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-27 21:55:15 -05:00
add and delete likes backend
This commit is contained in:
@@ -104,7 +104,6 @@ const FreeAgentsPage: React.FC<RouteComponentProps> = () => {
|
||||
|
||||
const showModalButton = () => {
|
||||
if (!userData.user) return false
|
||||
console.log("ownFAPost", ownFAPost)
|
||||
|
||||
if (ownFAPost && ownFAPost.hidden) {
|
||||
const weekFromCreatingFAPost = parseInt(ownFAPost.createdAt) + 604800000
|
||||
|
||||
@@ -4,6 +4,7 @@ const {
|
||||
gql,
|
||||
} = require("apollo-server-express")
|
||||
const FAPost = require("../mongoose-models/fapost")
|
||||
const FALike = require("../mongoose-models/falike")
|
||||
const sendFAPostToDiscord = require("../utils/webhook")
|
||||
|
||||
const canVCValues = ["YES", "USUALLY", "SOMETIMES", "NO"]
|
||||
@@ -32,6 +33,8 @@ const typeDef = gql`
|
||||
past_experience: String
|
||||
description: String
|
||||
): Boolean!
|
||||
addLike(discord_id: String!): Boolean!
|
||||
deleteLike(discord_id: String!): Boolean!
|
||||
}
|
||||
|
||||
enum CanVC {
|
||||
@@ -196,6 +199,46 @@ const resolvers = {
|
||||
})
|
||||
})
|
||||
|
||||
await FALike.deleteMany({
|
||||
$or: [
|
||||
{ liker_discord_id: ctx.user.discord_id },
|
||||
{ liked_discord_id: ctx.user.discord_id },
|
||||
],
|
||||
})
|
||||
|
||||
return true
|
||||
},
|
||||
addLike: async (root, args, ctx) => {
|
||||
if (!ctx.user) throw new AuthenticationError("Not logged in.")
|
||||
|
||||
const post = await FAPost.findOne({ discord_id: ctx.user.discord_id })
|
||||
|
||||
if (!post) {
|
||||
throw new UserInputError("Not a free agent")
|
||||
}
|
||||
|
||||
const likedPost = await FAPost.findOne({ discord_id: args.discord_id })
|
||||
|
||||
if (!likedPost) {
|
||||
throw new UserInputError("Liked user not a free agent")
|
||||
}
|
||||
|
||||
await FALike.findOneAndUpdate(
|
||||
{ liker_discord_id: ctx.user.discord_id },
|
||||
{
|
||||
liker_discord_id: ctx.user.discord_id,
|
||||
liked_discord_id: args.discord_id,
|
||||
},
|
||||
{ upsert: true }
|
||||
)
|
||||
|
||||
return true
|
||||
},
|
||||
deleteLike: async (root, args, ctx) => {
|
||||
if (!ctx.user) throw new AuthenticationError("Not logged in.")
|
||||
|
||||
await FALike.deleteOne({ liked_discord_id: args.discord_id })
|
||||
|
||||
return true
|
||||
},
|
||||
},
|
||||
|
||||
15
mongoose-models/falike.js
Normal file
15
mongoose-models/falike.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const mongoose = require("mongoose")
|
||||
|
||||
const faLikeSchema = new mongoose.Schema({
|
||||
liker_discord_id: String,
|
||||
liked_discord_id: String,
|
||||
})
|
||||
|
||||
/*mapBallotSchema.virtual("liker_discord_id", {
|
||||
ref: "User",
|
||||
localField: "discord_id",
|
||||
foreignField: "discord_id",
|
||||
justOne: true,
|
||||
})*/
|
||||
|
||||
module.exports = mongoose.model("FALike", faLikeSchema)
|
||||
Reference in New Issue
Block a user