-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapp.ts
More file actions
55 lines (40 loc) · 966 Bytes
/
app.ts
File metadata and controls
55 lines (40 loc) · 966 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { feathers } from 'feathers'
export type Message = {
id: number
text: string
createdAt: number
}
export class MessageService {
messages: Message[] = []
async find() {
return this.messages
}
async get(id: string) {
const message = this.messages.find((message) => message.id === parseInt(id))
if (!message) {
throw new Error(`Message not found`)
}
return message
}
async create(data: Pick<Message, 'text'>) {
const message = {
id: this.messages.length,
text: data.text,
createdAt: Date.now(),
}
this.messages.push(message)
return message
}
}
export type Services = {
messages: MessageService
}
const app = feathers<Services>()
app.use('messages', new MessageService())
app.service('messages').on('created', (message: Message) => {
console.log(`Message created: ${message.text}`)
})
app.service('messages').create({
text: 'Hello from server',
})
export { app }