aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/helpers/custom-validators/video-ownership.ts
blob: 9570b27995bd3bcc9f3b77fd163dec02a2fd165a (plain) (tree)
1
2
3
4
5
6
7
                                  
                                                                                     

                                                                                               
 

                                                                                 












                                                          
                                                                                                                                      
                                                          







                                                                            
import { Response } from 'express'
import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership'
import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership'
import { MUserId } from '@server/typings/models'

export async function doesChangeVideoOwnershipExist (id: number, res: Response) {
  const videoChangeOwnership = await VideoChangeOwnershipModel.load(id)

  if (!videoChangeOwnership) {
    res.status(404)
      .json({ error: 'Video change ownership not found' })
      .end()

    return false
  }

  res.locals.videoChangeOwnership = videoChangeOwnership
  return true
}

export function checkUserCanTerminateOwnershipChange (user: MUserId, videoChangeOwnership: MVideoChangeOwnershipFull, res: Response) {
  if (videoChangeOwnership.NextOwner.userId === user.id) {
    return true
  }

  res.status(403)
    .json({ error: 'Cannot terminate an ownership change of another user' })
    .end()
  return false
}