const moment = require('moment');
const { Expo } = require('expo-server-sdk');
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
const models = require('../../core/models');

const extraMethods = {
    isValidPushToken: (token) => {
        return Expo.isExpoPushToken(token);
    },

    afterFetchAll: (result, params, context) => {

        if (!result.count) {
            return result;
        }

        let rows = result.rows.map(row => row.toJSON());

        return {
            count: result.count,
            rows: rows
        }        
    },

     
    getPushToken: (params) => {
        return models.UserDevice.findOne({
            where: params,
        });
    },
};

module.exports = generateService(models.UserDevice, extraMethods);
