import express from 'express'
import {users} from './data'

export class UserController{
    login = (req: express.Request, res: express.Response)=>{
        let u = req.body.username;
        let p = req.body.password;

        let found = false
        for(let i=0; i<users.length; i++){
            if(users[i].username==u && users[i].password==p){
                found = true
                res.json(users[i])
            }
        }
        if(!found) res.json(null)
    }

    register = (req: express.Request, res: express.Response)=>{
        let user = req.body

        users.push(user)

        res.json("User added")
    }
}