blob: a6af023a4f19f285bcda6f237df90717c76bc723 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ChatRoom } from 'server/entities/chat_room.entity';
@Injectable()
export class ChatRoomService {
constructor(
@InjectRepository(ChatRoom)
private chatRoomRepository: Repository<ChatRoom>,
) {}
create(chatRoom: ChatRoom) {
return this.chatRoomRepository.save(chatRoom);
}
all() {
return this.chatRoomRepository.find();
}
near({ lat, lng }: { lat: number; lng: number }) {
return this.chatRoomRepository.query(
`SELECT * FROM chat_room WHERE calculate_distance(latitude, longitude, ${lat}, ${lng}, 'M') < 5`,
);
}
findById(id: number, relations: string[] = []) {
return this.chatRoomRepository.findOne(id, { relations });
}
save(chatRoom: ChatRoom) {
return this.chatRoomRepository.save(chatRoom);
}
remove(chatRoom: ChatRoom) {
return this.chatRoomRepository.remove(chatRoom);
}
}
|