Setting CRUD logic
The Model Abstract defines the interface. All that is left for you is to set the logic behind.

Overview

SugoiJS provides custom CRUD actions for models using the CRUD emitter.

Initialize

For CRUD support, you need to implement your CRUD logic under each of the CRUD emitters.

saveEmitter

1
public saveEmitter(options?:QueryOptions,data?:any): Promise<any> {
2
return rp({
3
method: 'POST',
4
uri: 'https://api.example.com/myendpoint',
5
body: data,
6
json: true
7
})
8
}
Copied!

findEmitter (static)

1
protected static findEmitter(query: any, options?:QueryOptions): Promise<any> {
2
return rp({
3
method: 'GET',
4
uri: 'https://api.example.com/myendpoint',
5
qs:query,
6
json: true
7
})
8
}
Copied!

updateEmitter

1
public updateEmitter(options?:QueryOptions,data:any): Promise<any> {
2
return rp({
3
method: 'PUT',
4
uri: `https://api.example.com/myendpoint/${this.id}`,
5
body: data,
6
json: true
7
})
8
}
Copied!

removeEmitter (static)

1
protected static removeEmitter(query?,options?:QueryOptions):Promise<any> {
2
return rp({
3
method: 'DELETE',
4
uri: `https://api.example.com/myendpoint/${query.id}`,
5
body: this,
6
json: true
7
})
8
}
Copied!
Last modified 2yr ago