File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,27 @@ export class FileController {
36
36
throw new Error ( 'File upload failed' ) ;
37
37
} ;
38
38
39
+ createTeamFile = async ( context : Context , teamId : string , file : File ) : Promise < any > => {
40
+ if ( ! this . isValidFile ( file ) )
41
+ throw new Error (
42
+ 'File must contain contentType, title, description and data'
43
+ ) ;
44
+
45
+ const serviceClient = await this . getServiceClient (
46
+ context . mongodb_provider ,
47
+ context . serviceKey
48
+ ) ;
49
+
50
+ file = await serviceClient . service . upload ( serviceClient . client , file ) ;
51
+
52
+ if ( file . uploaded ) {
53
+ const fileRepository = new FileRepository ( context . postgresql_provider ) ;
54
+ return fileRepository . saveFile ( teamId , file , context . serviceKey ) ;
55
+ }
56
+
57
+ throw new Error ( 'File upload failed' ) ;
58
+ }
59
+
39
60
/**
40
61
* gets file by id
41
62
* @param context context
Original file line number Diff line number Diff line change 5
5
import {
6
6
authorizedBy ,
7
7
ResponseCode ,
8
+ teamAuthorizedBy ,
9
+ TeamRole ,
8
10
UserRole ,
9
11
} from '@open-template-hub/common' ;
10
12
import { Request , Response } from 'express' ;
@@ -16,6 +18,7 @@ const subRoutes = {
16
18
root : '/' ,
17
19
me : '/me' ,
18
20
public : '/public' ,
21
+ team : '/team'
19
22
} ;
20
23
21
24
export const router = Router ( ) ;
@@ -50,3 +53,17 @@ router.get(
50
53
res . status ( ResponseCode . OK ) . json ( { file } ) ;
51
54
}
52
55
) ;
56
+
57
+ router . post (
58
+ subRoutes . team ,
59
+ teamAuthorizedBy ( [ TeamRole . CREATOR , TeamRole . WRITER ] ) ,
60
+ async ( req : Request , res : Response ) => {
61
+ let id = await fileController . createTeamFile (
62
+ res . locals . ctx ,
63
+ req . body . teamId ,
64
+ req . body . payload as File
65
+ ) ;
66
+
67
+ res . status ( ResponseCode . CREATED ) . json ( { id } ) ;
68
+ }
69
+ ) ;
You can’t perform that action at this time.
0 commit comments