import {
logger,
getMyPublicCert,
- getFormatedObjects
+ getFormattedObjects
} from '../../helpers'
import {
sendOwnedVideosToPod,
makeFriends,
- quitFriends
+ quitFriends,
+ removeFriend
} from '../../lib'
import {
podsAddValidator,
ensureIsAdmin,
makeFriendsValidator,
setBodyHostPort,
- setBodyHostsPort
+ setBodyHostsPort,
+ podRemoveValidator
} from '../../middlewares'
import {
PodInstance
} from '../../models'
-import { Pod as FormatedPod } from '../../../shared'
+import { Pod as FormattedPod } from '../../../shared'
const podsRouter = express.Router()
podsAddValidator,
addPods
)
-podsRouter.post('/makefriends',
+podsRouter.post('/make-friends',
authenticate,
ensureIsAdmin,
makeFriendsValidator,
setBodyHostsPort,
makeFriendsController
)
-podsRouter.get('/quitfriends',
+podsRouter.get('/quit-friends',
authenticate,
ensureIsAdmin,
quitFriendsController
)
+podsRouter.delete('/:id',
+ authenticate,
+ ensureIsAdmin,
+ podRemoveValidator,
+ removeFriendController
+)
// ---------------------------------------------------------------------------
function listPods (req: express.Request, res: express.Response, next: express.NextFunction) {
db.Pod.list()
- .then(podsList => res.json(getFormatedObjects<FormatedPod, PodInstance>(podsList, podsList.length)))
+ .then(podsList => res.json(getFormattedObjects<FormattedPod, PodInstance>(podsList, podsList.length)))
.catch(err => next(err))
}
.then(() => res.type('json').status(204).end())
.catch(err => next(err))
}
+
+function removeFriendController (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const pod = res.locals.pod as PodInstance
+
+ removeFriend(pod)
+ .then(() => (res.type('json').status(204).end()))
+ .catch(err => next(err))
+}