Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

138 login through google #141

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddUserEntity1729046542663 implements MigrationInterface {
name = 'AddUserEntity1729046542663'
export class AddUserEntity1729108227487 implements MigrationInterface {
name = 'AddUserEntity1729108227487'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "google_user" ("id" SERIAL NOT NULL, "name" character varying NOT NULL, "email" character varying NOT NULL, "picture" character varying, CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "google_user" ("id" SERIAL NOT NULL, "name" character varying NOT NULL, "email" character varying NOT NULL, "picture" character varying, "createdOn" TIMESTAMP NOT NULL DEFAULT now(), "updatedOn" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_327db3e0d20823d96ed80889431" PRIMARY KEY ("id"))`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
Expand Down
10 changes: 8 additions & 2 deletions apps/api/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";

@Entity({ name: 'google_user' })
export class User {
Expand All @@ -13,4 +13,10 @@ export class User {

@Column({ nullable: true })
picture: string;
}

@CreateDateColumn()
createdOn: Date;

@UpdateDateColumn()
updatedOn: Date;
}
9 changes: 5 additions & 4 deletions apps/api/src/user/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ export class UsersService {

async login(userToLogin: UserCreateDTO): Promise<UserDTO> {
const existingUser = await this.userRepository.findOne({ where: { email: userToLogin.email } });
console.log('existing user', existingUser);
if (existingUser !== null && existingUser !== undefined) {
existingUser.name = userToLogin.name;
existingUser.picture = userToLogin.picture;
await this.userRepository.save(userToLogin);
await this.userRepository.update({ id: existingUser.id }, { name: userToLogin.name, picture: userToLogin.picture });
return { name: existingUser.name, email: existingUser.email, picture: existingUser.picture };
}

const newUser = await this.userRepository.create(userToLogin);
console.log('new user', newUser);
await this.userRepository.save(newUser);
if (newUser !== null && newUser !== newUser) {
if (newUser !== undefined && newUser !== null) {
return { name: newUser.name, email: newUser.email, picture: newUser.picture };
}
console.log('no existing, no new');
return null;
}
}