Your IP : 216.73.216.91


Current Path : /var/node/inatote/Inatote-Backend/chat/
Upload File :
Current File : /var/node/inatote/Inatote-Backend/chat/chat.js

import requiredParam from '../helpers/required-param.js'
import { InvalidPropertyError } from '../helpers/errors.js'
import isValidEmail from '../helpers/is-valid-email.js'
import upperFirst from '../helpers/upper-first.js'

export default function makeChat(chatInfo = requiredParam('ChatInfo')) {
    const validateChat = validate(chatInfo)
    const normalizeChat = normalize(validateChat)
    return Object.freeze(normalizeChat)

    function validate({
        to = requiredParam('to'),
        from = requiredParam('from'),
        message = requiredParam('message'),
        ...otherInfo
    } = {}) {

        validateTo(to)
        validateFrom(from)
        // validateMessage(message)
        
        return { to, from, message,...otherInfo }

        function validateTo(type) {
            //console.log("sender" , type ,type.length , typeof type );
           if (typeof type != "string" && type.length < 24) {
                
                throw new InvalidPropertyError(
                    `Sender Id is not proper`
                )
            }
        }

        function validateFrom(type) {
            if (typeof type != "string" && type.length < 24) {
                 
                 throw new InvalidPropertyError(
                     `Rider Id is not proper`
                 )
             }
         }


       

      
    }


    function normalize({ ...otherInfo }) {
        return {
            ...otherInfo,
        }
    }
}