|
|
@@ -6,8 +6,10 @@ import Ws from 'App/Services/Ws'
|
|
|
export default class PhishesController {
|
|
|
private paginationService = new PaginationService(Phish)
|
|
|
|
|
|
- public async index({ request }: HttpContextContract) {
|
|
|
- return await this.paginationService.paginate(request.all())
|
|
|
+ public async index({ request, auth }: HttpContextContract) {
|
|
|
+ return await this.paginationService.paginate(request.all(), (q) => {
|
|
|
+ q.where('userId', auth.user!.id).orWhereNull('userId')
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
public async store({ request }: HttpContextContract) {
|
|
|
@@ -46,4 +48,14 @@ export default class PhishesController {
|
|
|
Ws.phishIO.to(phish.socketId).emit('update', phish)
|
|
|
return phish
|
|
|
}
|
|
|
+
|
|
|
+ public async claim({ params, auth }: HttpContextContract) {
|
|
|
+ const phish = await Phish.findOrFail(params.id)
|
|
|
+ if (phish.userId && phish.userId !== auth.user!.id) {
|
|
|
+ throw new Error('已被他人领取')
|
|
|
+ }
|
|
|
+ phish.userId = auth.user!.id
|
|
|
+ await phish.save()
|
|
|
+ return phish
|
|
|
+ }
|
|
|
}
|