add email to users

This commit is contained in:
2019-01-02 23:29:00 +03:00
parent 733cbb4f26
commit 29a035912b
4 changed files with 22 additions and 8 deletions

View File

@@ -29,12 +29,17 @@ export class User extends BaseEntity {
@Index({ unique: true })
public username: string;
@Column()
@Index({ unique: true })
public email: string;
@Column()
public passwordHash: string;
constructor(username: string) {
constructor(username: string, email: string) {
super();
this.username = username;
this.email = email;
}
public async verifyPassword(password: string) {

View File

@@ -45,16 +45,17 @@ userRouter.post("/users/signup", async ctx => {
ctx.throw(400);
}
const { username, password } = request.body as {
const { username, password, email } = request.body as {
username: string | null;
password: string | null;
email: string | null;
};
if (!(username && password)) {
if (!(username && password && email)) {
ctx.throw(400);
}
const user = new User(username);
const user = new User(username, email);
await user.setPassword(password);
try {

View File

@@ -71,7 +71,11 @@ describe("users", () => {
const response = await request(callback)
.post("/users/signup")
.set({ "Content-Type": "application/json" })
.send({ username: "NUser1", password: "NUser1" })
.send({
username: "NUser1",
password: "NUser1",
email: "nuser1@users.com",
})
.expect("Content-Type", /json/)
.expect(200);
@@ -88,7 +92,11 @@ describe("users", () => {
const response = await request(callback)
.post("/users/signup")
.set({ "Content-Type": "application/json" })
.send({ username: "User1", password: "NUser1" })
.send({
username: "User1",
password: "NUser1",
email: "user1@users.com",
})
.expect(400);
expect(response.body.error).to.be.equal("User already exists");

View File

@@ -8,11 +8,11 @@ export interface ISeed {
export async function seedDB(): Promise<ISeed> {
await User.remove(await User.find());
const user1 = new User("User1");
const user1 = new User("User1", "user1@users.com");
await user1.setPassword("User1");
await user1.save();
const user2 = new User("User2");
const user2 = new User("User2", "user2@users.com");
await user2.setPassword("User2");
await user2.save();