Skip to content

Commit

Permalink
feat(bids): auth and users count
Browse files Browse the repository at this point in the history
  • Loading branch information
Vekeryk committed May 24, 2024
1 parent b46333f commit 4185132
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 76 deletions.
45 changes: 6 additions & 39 deletions apps/auction/src/lots/lot.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,8 @@ export class Lot extends GenericEntity {
@ManyToMany(() => Tag, { eager: true })
@JoinTable({
name: 'lot_tags',
joinColumn: {
name: 'lot_id',
referencedColumnName: 'id',
},
inverseJoinColumn: {
name: 'tag_id',
referencedColumnName: 'id',
},
joinColumn: { name: 'lot_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'tag_id', referencedColumnName: 'id' },
})
tags: Tag[];

Expand All @@ -112,11 +106,7 @@ export class Lot extends GenericEntity {
@OneToMany(() => LotImage, (lotImage) => lotImage.lot, { eager: true })
images: LotImage[];

@Column({
type: 'enum',
enum: LotStatus,
default: LotStatus.PENDING,
})
@Column({ type: 'enum', enum: LotStatus, default: LotStatus.PENDING })
status: LotStatus;

@Column({ type: 'timestamp', nullable: false })
Expand All @@ -126,35 +116,12 @@ export class Lot extends GenericEntity {
endTime: Date;

@Column({ type: 'int', nullable: false })
startingPrice: number;

@Column({ type: 'int', nullable: true })
currentPrice: number;
price: number;

@Column({
type: 'enum',
enum: PaymentMethod,
array: true,
})
@Column({ type: 'enum', enum: PaymentMethod, array: true })
paymentMethods: PaymentMethod[];

@Column({
type: 'enum',
enum: DeliveryMethod,
array: true,
})
deliveryMethods: DeliveryMethod[];

@Column({
type: 'enum',
enum: Location,
})
location: Location;

@Column({
type: 'enum',
enum: DealType,
})
@Column({ type: 'enum', enum: DealType })
dealType: DealType;

@CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
Expand Down
35 changes: 7 additions & 28 deletions apps/auction/src/users/user.enitity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,28 @@ export class User {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({
length: 128,
unique: true,
nullable: false,
})
@Column({ length: 128, unique: true, nullable: false })
username: string;

@Column({
length: 128,
unique: true,
nullable: false,
})
@Column({ length: 128, unique: true, nullable: false })
email: string;

@Column('text')
passwordHash: string;

@Column({
length: 128,
})
@Column({ length: 128 })
firstName: string;

@Column({
length: 128,
})
@Column({ length: 128 })
lastName: string;

@Column({
type: 'int',
default: 0,
})
@Column({ type: 'int', default: 0 })
balance: number;

@Column({
type: 'int',
default: 0,
})
@Column({ type: 'int', default: 0 })
rating: number;

@Column({
length: 128,
nullable: true,
})
@Column({ length: 128, nullable: true })
profilePicture: string;

@OneToMany(() => Notification, (notification) => notification.user)
Expand Down
5 changes: 4 additions & 1 deletion apps/bids/src/bids.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ConfigModule } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';

import { AuthService } from '@app/common/services/auth.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';

import { Bid } from './bid.entity';
import { BidsController } from './bids.controller';
import { BidsService } from './bids.service';
import { BidsGateway } from './bids.gateway';

@Module({
imports: [
Expand Down Expand Up @@ -44,6 +47,6 @@ import { BidsService } from './bids.service';
TypeOrmModule.forFeature([Bid]),
],
controllers: [BidsController],
providers: [BidsService],
providers: [BidsService, AuthService, BidsGateway],
})
export class BidsModule {}
1 change: 1 addition & 0 deletions apps/bids/src/bids.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class BidsService extends GenericCrudService<Bid> {
'The bid amount must be higher than the current highest bid.',
);
}
console.log('Placing Bid...');
const placedBid = await this.create({ ...placeBidDto, userId: user.id });
this.rabbitClient.emit('bid-placed', placedBid);
return placedBid;
Expand Down
27 changes: 27 additions & 0 deletions libs/common/src/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { KeycloakUserPayload, UserRole } from '@app/common/types';

@Injectable()
export class AuthService {
constructor(private readonly jwtService: JwtService) {}

async validateToken(token: string) {
const secret = `-----BEGIN PUBLIC KEY-----\n${process.env.KEYCLOAK_PUBLIC_KEY}\n-----END PUBLIC KEY-----`;
console.log(secret);
const payload = await this.jwtService.verifyAsync<KeycloakUserPayload>(
token,
{ secret },
);
return {
id: payload.sid,
role: UserRole.USER,
username: payload.preferred_username,
email: payload.email,
emailVerified: payload.email_verified,
firstName: payload.given_name,
lastName: payload.family_name,
fullName: payload.name,
};
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"@nestjs/jwt": "^10.2.0",
"@nestjs/microservices": "^10.3.8",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.3.8",
"@nestjs/typeorm": "^10.0.2",
"@nestjs/websockets": "^10.3.8",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.4",
"class-transformer": "^0.5.1",
Expand Down
Loading

0 comments on commit 4185132

Please sign in to comment.