Skip to content

Commit

Permalink
fix: correct database loading backfill not saving user
Browse files Browse the repository at this point in the history
  • Loading branch information
0-vortex committed Nov 10, 2022
1 parent a31869b commit 7cfc04b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/user/user.service.ts
Expand Up @@ -40,21 +40,26 @@ export class UserService {
}

async checkAddUser (user: User): Promise<DbUser> {
const { user_metadata: { sub: id, user_name } } = user;
const { user_metadata: { user_name }, identities } = user;
const github = identities!.filter(identity => identity.provider === "github")[0];
const id = parseInt(github.id, 10);

try {
const publicUser = await this.findOneById(id as number);
const publicUser = await this.findOneById(id);

return publicUser;
} catch (e) {
// create new user
const newUser = this.userRepository.create({
id: id as number,
id,
is_open_sauced_member: false,
login: user_name as string,
created_at: new Date().toString(), // eslint-disable-line
created_at: new Date(github.created_at),
updated_at: new Date(github.updated_at ?? github.created_at),
});

// return new user
await newUser.save();

return newUser;
}
}
Expand Down

0 comments on commit 7cfc04b

Please sign in to comment.