feat: add connection API endpoints
Suggestions, create/confirm/hide/withdraw actions, my connections list, and pending count for nav badge.
This commit is contained in:
parent
d69d21abd6
commit
dcb80e6006
7 changed files with 442 additions and 0 deletions
45
server/api/connections/index.get.js
Normal file
45
server/api/connections/index.get.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import Connection from '../../models/connection.js'
|
||||
import { requireAuth } from '../../utils/auth.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const member = await requireAuth(event)
|
||||
const memberId = member._id
|
||||
|
||||
const [confirmed, pendingOutgoing, pendingIncoming] = await Promise.all([
|
||||
Connection.find({
|
||||
status: 'confirmed',
|
||||
hiddenBy: { $ne: memberId },
|
||||
$or: [
|
||||
{ initiator: memberId },
|
||||
{ recipient: memberId }
|
||||
]
|
||||
})
|
||||
.populate('initiator recipient', 'name avatar craftTags circle')
|
||||
.sort({ confirmedAt: -1 })
|
||||
.lean(),
|
||||
|
||||
Connection.find({
|
||||
initiator: memberId,
|
||||
status: 'pending',
|
||||
hiddenBy: { $ne: memberId }
|
||||
})
|
||||
.populate('recipient', 'name avatar craftTags circle')
|
||||
.sort({ createdAt: -1 })
|
||||
.lean(),
|
||||
|
||||
Connection.find({
|
||||
recipient: memberId,
|
||||
status: 'pending',
|
||||
hiddenBy: { $ne: memberId }
|
||||
})
|
||||
.populate('initiator', 'name avatar craftTags circle')
|
||||
.sort({ createdAt: -1 })
|
||||
.lean()
|
||||
])
|
||||
|
||||
return {
|
||||
confirmed,
|
||||
pendingOutgoing,
|
||||
pendingIncoming
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue