1- import { Model } from '../../../model' ;
2- import { RelationQueryBuilder } from '../builders/relationQueryBuilder' ;
3- import { HttpMethod } from '../enums/httpMethod' ;
4- import { AttachResult } from '../results/attachResult' ;
5- import { ExtractModelAttributesType } from '../../../types/extractModelAttributesType' ;
6- import { DetachResult } from '../results/detachResult' ;
7- import { SyncResult } from '../results/syncResult' ;
8- import { ToggleResult } from '../results/toggleResult' ;
9- import { UpdatePivotResult } from '../results/updatePivotResult' ;
10- import { ExtractModelPersistedAttributesType } from '../../../types/extractModelPersistedAttributesType' ;
11- import { ExtractModelRelationsType } from '../../../types/extractModelRelationsType' ;
1+ import { Model } from '../../../model' ;
2+ import { RelationQueryBuilder } from '../builders/relationQueryBuilder' ;
3+ import { HttpMethod } from '../enums/httpMethod' ;
4+ import { AttachResult } from '../results/attachResult' ;
5+ import { ExtractModelAttributesType } from '../../../types/extractModelAttributesType' ;
6+ import { DetachResult } from '../results/detachResult' ;
7+ import { SyncResult } from '../results/syncResult' ;
8+ import { ToggleResult } from '../results/toggleResult' ;
9+ import { UpdatePivotResult } from '../results/updatePivotResult' ;
10+ import {
11+ ExtractModelPersistedAttributesType
12+ } from '../../../types/extractModelPersistedAttributesType' ;
13+ import { ExtractModelRelationsType } from '../../../types/extractModelRelationsType' ;
1214
1315export class BelongsToMany <
1416 Relation extends Model ,
@@ -21,10 +23,10 @@ export class BelongsToMany<
2123 keys : Array < number | string > ,
2224 duplicates : boolean = false
2325 ) : Promise < AttachResult > {
24- const response = await this . httpClient . request (
26+ const response = await this . httpClient . request < { attached : Array < number | string > } > (
2527 `/attach` ,
2628 HttpMethod . POST ,
27- { duplicates : duplicates ? 1 : 0 } ,
29+ { duplicates : duplicates ? 1 : 0 } ,
2830 {
2931 resources : keys ,
3032 }
@@ -37,37 +39,39 @@ export class BelongsToMany<
3739 resources : Record < string , Pivot > ,
3840 duplicates : boolean = false
3941 ) : Promise < AttachResult > {
40- const response = await this . httpClient . request (
42+ const response = await this . httpClient . request < { attached : Array < number | string > } > (
4143 `/attach` ,
4244 HttpMethod . POST ,
43- { duplicates : duplicates ? 1 : 0 } ,
44- { resources }
45+ { duplicates : duplicates ? 1 : 0 } ,
46+ { resources}
4547 ) ;
4648
4749 return new AttachResult ( response . data . attached ) ;
4850 }
4951
5052 public async detach ( keys : Array < number | string > ) : Promise < DetachResult > {
51- const response = await this . httpClient . request ( `/detach` , HttpMethod . DELETE , null , {
53+ const response = await this . httpClient . request < { detached : Array < number | string > } > ( `/detach` , HttpMethod . DELETE , null , {
5254 resources : keys ,
5355 } ) ;
5456
5557 return new DetachResult ( response . data . detached ) ;
5658 }
5759
5860 public async detachWithFields ( resources : Record < string , Pivot > ) : Promise < DetachResult > {
59- const response = await this . httpClient . request ( `/detach` , HttpMethod . DELETE , null , {
61+ const response = await this . httpClient . request < { detached : Array < number | string > } > ( `/detach` , HttpMethod . DELETE , null , {
6062 resources,
6163 } ) ;
6264
6365 return new DetachResult ( response . data . detached ) ;
6466 }
6567
6668 public async sync ( keys : Array < number | string > , detaching : boolean = true ) : Promise < SyncResult > {
67- const response = await this . httpClient . request (
69+ const response = await this . httpClient . request <
70+ { attached : Array < number | string > , updated : Array < number | string > , detached : Array < number | string > }
71+ > (
6872 `/sync` ,
6973 HttpMethod . PATCH ,
70- { detaching : detaching ? 1 : 0 } ,
74+ { detaching : detaching ? 1 : 0 } ,
7175 {
7276 resources : keys ,
7377 }
@@ -80,34 +84,40 @@ export class BelongsToMany<
8084 resources : Record < string , Pivot > ,
8185 detaching : boolean = true
8286 ) : Promise < SyncResult > {
83- const response = await this . httpClient . request (
87+ const response = await this . httpClient . request <
88+ { attached : Array < number | string > , updated : Array < number | string > , detached : Array < number | string > }
89+ > (
8490 `/sync` ,
8591 HttpMethod . PATCH ,
86- { detaching : detaching ? 1 : 0 } ,
87- { resources }
92+ { detaching : detaching ? 1 : 0 } ,
93+ { resources}
8894 ) ;
8995
9096 return new SyncResult ( response . data . attached , response . data . updated , response . data . detached ) ;
9197 }
9298
9399 public async toggle ( keys : Array < number | string > ) : Promise < ToggleResult > {
94- const response = await this . httpClient . request ( `/toggle` , HttpMethod . PATCH , null , {
100+ const response = await this . httpClient . request <
101+ { attached : Array < number | string > , detached : Array < number | string > }
102+ > ( `/toggle` , HttpMethod . PATCH , null , {
95103 resources : keys ,
96104 } ) ;
97105
98106 return new ToggleResult ( response . data . attached , response . data . detached ) ;
99107 }
100108
101109 public async toggleWithFields ( resources : Record < string , Pivot > ) : Promise < ToggleResult > {
102- const response = await this . httpClient . request ( `/toggle` , HttpMethod . PATCH , null , {
110+ const response = await this . httpClient . request <
111+ { attached : Array < number | string > , detached : Array < number | string > }
112+ > ( `/toggle` , HttpMethod . PATCH , null , {
103113 resources,
104114 } ) ;
105115
106116 return new ToggleResult ( response . data . attached , response . data . detached ) ;
107117 }
108118
109119 public async updatePivot ( key : number | string , pivot : Pivot ) : Promise < UpdatePivotResult > {
110- const response = await this . httpClient . request ( `/${ key } /pivot` , HttpMethod . PATCH , null , {
120+ const response = await this . httpClient . request < { updated : Array < string | number > } > ( `/${ key } /pivot` , HttpMethod . PATCH , null , {
111121 pivot,
112122 } ) ;
113123
0 commit comments