"use strict";
// import { genSalt, hash, compare } from 'bcrypt'
Object.defineProperty(exports, "__esModule", { value: true });
const typeorm_1 = require("typeorm");
const entities_1 = require("../entities");
async function signup(attrs) {
    const repository = typeorm_1.getRepository(entities_1.User);
    const old = await repository.findOne({ email: attrs.email });
    if (old) {
        throw new Error('user duplicated.');
    }
    // const salt = await genSalt(10)
    // const hashed = await hash(attrs.password, salt, null)
    attrs = Object.assign({ userType: 'user' }, attrs, { password: entities_1.User.encode(attrs.password) });
    const user = await repository.save(Object.assign({}, attrs));
    delete user.password;
    return user;
}
exports.signup = signup;
async function signin(attrs) {
    const repository = typeorm_1.getRepository(entities_1.User);
    const user = await repository.findOne({ email: attrs.email });
    console.log('signin---------', attrs.email, user);
    if (!user) {
        throw new Error('user notfound.');
    }
    if (!user.veryfy(attrs.password)) {
        throw new Error('password not match.');
    }
    return user;
}
exports.signin = signin;
//# sourceMappingURL=auth.js.map