const routes = require('express').Router();

const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
const SchemaValidator = require('../../middlewares/schemaValidator');

const FieldMiddleware = require('../../middlewares/fields');
const pushTokenController = require('./push.controller');
const { pushInputType } = require('./push.validations');

const generalInvalidFields = [
    'createdAt', 'updatedAt',
];

routes.get('/me/pushtoken',
    isLoggedUser,    
    FieldMiddleware.middleware({
        invalidFields: generalInvalidFields
    }),
    pushTokenController.findOne()
);

routes.post('/me/pushtoken',
    isLoggedUser,
    SchemaValidator(pushInputType, true), 
    pushTokenController.createOrUpdate()
);

module.exports = routes;