Skip to content

Commit

Permalink
Merge pull request #144 from boostcampwm-2024/be/fix/chartdata
Browse files Browse the repository at this point in the history
[BE/fix] crops 데이터 수정
  • Loading branch information
HBLEEEEE authored Dec 2, 2024
2 parents 7ffc63d + 3e4639d commit 2bd9afb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/backend/src/chart/chart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { InjectModel } from '@nestjs/mongoose';
import { Chart } from './model/chart.schema';
import { Model } from 'mongoose';
import { Cron, CronExpression } from '@nestjs/schedule';
// import { WebsocketGateway } from 'src/websocket/websocket.gateway';

@Injectable()
export class ChartService implements OnModuleInit {
constructor(
// private readonly webSocketGateway: WebsocketGateway,
private readonly databaseService: DatabaseService,
@InjectModel(Chart.name) private readonly chartModel: Model<Chart>
) {}
Expand Down
12 changes: 10 additions & 2 deletions apps/backend/src/websocket/websocket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class WebsocketGateway implements OnGatewayInit, OnGatewayConnection, OnG
}

async handleConnection(client: Socket) {
const token = client.handshake.auth.authorization?.split(': ')[1];
const token = client.handshake.auth.authorization?.split(' ')[1];
if (!token) {
client.disconnect(true);
return;
Expand Down Expand Up @@ -101,7 +101,15 @@ export class WebsocketGateway implements OnGatewayInit, OnGatewayConnection, OnG
`;

const crops = await this.databaseService.query(query, [memberId]);
client.emit('crops', crops.rows);

const data = crops.rows.map(crop => ({
cropId: crop.crop_id,
availableQuantity: crop.available_quantity,
pendingQuantity: crop.pending_quantity,
totalQuantity: crop.total_quantity
}));

client.emit('crops', data);
}

private async handleRedisUpdate(cropId: string) {
Expand Down

0 comments on commit 2bd9afb

Please sign in to comment.