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 FormattedPod } from '../../../shared'
const podsRouter = express.Router()
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(podsList, podsList.length)))
+ .then(podsList => res.json(getFormattedObjects<FormattedPod, PodInstance>(podsList, podsList.length)))
.catch(err => next(err))
}
makeFriends(hosts)
.then(() => logger.info('Made friends!'))
- .catch(err => logger.error('Could not make friends.', { error: err }))
+ .catch(err => logger.error('Could not make friends.', err))
// Don't wait the process that could be long
res.type('json').status(204).end()
.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))
+}