1+ "use strict" ;
2+
3+ import { Queryable , QueryableCollection , QueryableInstance } from "./queryable" ;
4+ import { QueryableSecurable } from "./queryablesecurable" ;
5+ import { TypedHash } from "../../collections/collections" ;
6+ import { Util } from "../../utils/util" ;
7+ import * as Types from "./types" ;
8+ import { ODataParserBase } from "./odata" ;
9+
10+ /**
11+ * Describes a collection of Item objects
12+ *
13+ */
14+ export class AttachmentFiles extends QueryableCollection {
15+
16+ /**
17+ * Creates a new instance of the AttachmentFiles class
18+ *
19+ * @param baseUrl The url or Queryable which forms the parent of this attachments collection
20+ */
21+ constructor ( baseUrl : string | Queryable , path = "AttachmentFiles" ) {
22+ super ( baseUrl , path ) ;
23+ }
24+
25+ /**
26+ * Gets a Attachment File by filename
27+ *
28+ * @param name The name of the file, including extension.
29+ */
30+ public getByName ( name : string ) : AttachmentFile {
31+ let f = new AttachmentFile ( this ) ;
32+ f . concat ( `(FileName='${ name } ')` ) ;
33+ return f ;
34+ }
35+
36+ /**
37+ * Adds a new attachment to the collection
38+ *
39+ * @param name The name of the file, including extension.
40+ * @param content The Base64 file content.
41+ */
42+ public add ( name : string , content : string ) : Promise < AttachmentFileAddResult > {
43+ return new AttachmentFiles ( this , `add(FileName='${ name } ')` )
44+ . post ( {
45+ // binaryStringRequestBody: true,
46+ body : content
47+ } ) . then ( ( response ) => {
48+ return {
49+ data : response ,
50+ file : this . getByName ( name ) ,
51+ } ;
52+ } ) ;
53+ }
54+ }
55+
56+ /**
57+ * Descrines a single attachment file instance
58+ *
59+ */
60+ export class AttachmentFile extends QueryableSecurable {
61+
62+ /**
63+ * Creates a new instance of the AttachmentFile class
64+ *
65+ * @param baseUrl The url or Queryable which forms the parent of this attachment file
66+ */
67+ constructor ( baseUrl : string | Queryable , path ?: string ) {
68+ super ( baseUrl , path ) ;
69+ }
70+
71+ /**
72+ * Delete this attachment file
73+ *
74+ * @param eTag Value used in the IF-Match header, by default "*"
75+ */
76+ public delete ( eTag = "*" ) : Promise < void > {
77+ return this . post ( {
78+ headers : {
79+ "IF-Match" : eTag ,
80+ "X-HTTP-Method" : "DELETE" ,
81+ } ,
82+ } ) ;
83+ }
84+ }
85+
86+ export interface AttachmentFileAddResult {
87+ file : AttachmentFile ;
88+ data : any ;
89+ }
0 commit comments