my-chat-room/apps/api/src/app/app.service.ts

19 lines
443 B
TypeScript
Raw Normal View History

2020-10-09 13:32:53 +00:00
import { Injectable } from '@nestjs/common';
import { Message } from '@chat-room/api-interfaces';
@Injectable()
export class AppService {
2020-10-09 16:21:21 +00:00
private messages: Message[] = [];
getMessages(): Message[] {
return this.messages;
}
addMessage(message: Message): Message {
this.messages.push(message);
// Only keep the last 60 messages
this.messages = this.messages.reverse().slice(0, 60).reverse();
return message;
2020-10-09 13:32:53 +00:00
}
}