-
Notifications
You must be signed in to change notification settings - Fork 2
/
attachment.ts
52 lines (46 loc) · 1.82 KB
/
attachment.ts
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
import { ChallongeBase, MatchAttachmentAdapter, MatchAttachmentInterfaces } from './';
export default class Attachment extends ChallongeBase {
user_id: number;
description?: string;
url?: string;
original_file_name?: string;
created_at?: Date;
updated_at?: Date;
asset_file_name?: string;
asset_content_type?: string;
asset_file_size?: number;
asset_url?: string;
constructor(public api_key: string, public baseUrl: string, public match_id: number, public id: number, data?: MatchAttachmentInterfaces.matchAttachmentResponseObject) {
super(api_key);
if(data){
Object.assign(this, data);
}
}
/** Retrieve a single match attachment record. */
public get(): Promise<Attachment> {
return new Promise((resolve, reject) => {
MatchAttachmentAdapter.show(this.api_key, this.baseUrl, this.match_id, this.id).then(res => {
Object.assign(this, res.match_attachment);
resolve(this);
}).catch(err => reject(err));
});
}
/** Update the attributes of a match attachment. */
public update(params?: MatchAttachmentInterfaces.matchAttachmentRequestObject): Promise<Attachment> {
return new Promise((resolve, reject) => {
MatchAttachmentAdapter.update(this.api_key, this.baseUrl, this.match_id, this.id, { match_attachment: params }).then(res => {
Object.assign(this, res.match_attachment);
resolve(this);
}).catch(err => reject(err));
});
}
/** Delete a match attachment. */
public delete(): Promise<boolean> {
return new Promise((resolve, reject) => {
MatchAttachmentAdapter.destroy(this.api_key, this.baseUrl, this.match_id, this.id).then(res => {
if(res.status = 200) { this.api_key = undefined; resolve(true); }
else { reject({error: 'Challonge did not return 200'}) }
}).catch(err => reject(err));
});
}
}