• File: Push.js
  • Full Path: /var/www/nodejs/Notifications_Imali_API/src/models/Push.js
  • Date Modified: 02/26/2025 1:00 PM
  • File size: 1.24 KB
  • MIME-type: text/x-c++
  • Charset: utf-8
const Joi = require("joi");
const env = process.env;

class Push {

    constructor(title,message){
    
        // if(fire_token.length === 1)
            // this.to=fire_token[0];h
        // else
            // this.registration_ids=fire_token;

        this.notification=new NotificationConf(title,message);
        this.data=new PushData(message)
    }

    static validate(body){
        return Joi.object({
            to:Joi.array().required(),
            subject:Joi.string().required().max(30),
            message:Joi.string().required().max(500),
        }).validate(body);

    }

}

class NotificationConf{
    constructor(subject,message){
        this.icon = 'ic_i_mali_cover';
        this.click_action ='com.imali.payapp.payment_NOTICIA';
        this.color ='#ffffff';
        this.title=subject;
        this.body=message;
    }
}

class PushData{
    constructor(message){
        this.sms = message;
        this.terminal ='firebase';
    }
}

class PushConf{  
    constructor(){
        this.responseType='json';
        this.headers = {
            'Authorization': `key=${env.PUSH_AUTHORIZATION_TOKEN}`,
            'Content-Type': 'application/json',
            'Accept':'application/json'
        }
    }
}

module.exports={Push,PushConf};