Skip to content

Commit

Permalink
📝 Docs: moment 라이브러리 추가 및 chat message timestamp format 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
황세민 authored and 황세민 committed Jul 4, 2024
1 parent 5990db9 commit f39b7f2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"g": "^2.0.1",
"ioredis": "^5.4.1",
"joi": "^17.13.1",
"moment": "^2.30.1",
"mongoose": "^8.4.0",
"multer": "^1.4.5-lts.1",
"nest": "^0.1.6",
Expand Down
4 changes: 4 additions & 0 deletions src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DataSource, Repository } from 'typeorm';
import { Message } from './entities/message.entity';
import { Room } from './entities/room.entity';
import { v4 as uuidv4 } from 'uuid';
import moment from 'moment';

@Injectable()
export class ChatService {
Expand Down Expand Up @@ -97,10 +98,13 @@ export class ChatService {
return;
}

const timestamp = moment().format('YYYY-MM-DD HH:mm:ss');

const messageInfo = await this.messageModel.create({
sender: userId,
content: data.message,
room: data.room,
timestamp: timestamp,
});

const foundUserNickname = await this.userService.findUserNameById(userId);
Expand Down
2 changes: 1 addition & 1 deletion src/chat/entities/message.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Message extends Document {
room: string;

@Prop({ default: Date.now() })
timestamp: Date;
timestamp: string;
}

export const MessageSchema = SchemaFactory.createForClass(Message);

0 comments on commit f39b7f2

Please sign in to comment.