Commit 0dcf686 1 parent 31a3ed1 commit 0dcf686 Copy full SHA for 0dcf686
File tree 5 files changed +46
-3
lines changed
5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,13 @@ import Usecase from '../../usecase/usecase'
4
4
import { NextFunction , Request , Response } from 'express'
5
5
import statusCode from '../../../../pkg/statusCode'
6
6
import { GetMeta , GetRequestParams } from '../../../../helpers/requestParams'
7
- import { ValidateFormRequest } from '../../../../helpers/validate'
8
- import { Store } from '../../entity/schema'
7
+ import {
8
+ ValidateFormRequest ,
9
+ ValidateParams ,
10
+ } from '../../../../helpers/validate'
11
+ import { Search , Store } from '../../entity/schema'
9
12
import { unlinkSync } from 'fs'
13
+ import error from '../../../../pkg/error'
10
14
11
15
class Handler {
12
16
constructor (
@@ -70,6 +74,25 @@ class Handler {
70
74
}
71
75
}
72
76
}
77
+
78
+ public Search ( ) {
79
+ return async ( req : any , res : Response , next : NextFunction ) => {
80
+ try {
81
+ const value = ValidateFormRequest ( Search , req . query )
82
+ const isExist = await this . usecase . Search ( value )
83
+ this . logger . Info ( statusCode [ statusCode . OK ] , {
84
+ additional_info : this . http . AdditionalInfo (
85
+ req ,
86
+ statusCode . OK
87
+ ) ,
88
+ } )
89
+ const message = isExist ? 'Available' : 'Not Available'
90
+ return res . status ( statusCode . OK ) . json ( { message } )
91
+ } catch ( error ) {
92
+ return next ( error )
93
+ }
94
+ }
95
+ }
73
96
}
74
97
75
98
export default Handler
Original file line number Diff line number Diff line change @@ -15,3 +15,8 @@ export interface File {
15
15
filename : string
16
16
uri ?: string
17
17
}
18
+
19
+ export type Search = {
20
+ category : string
21
+ filename : string
22
+ }
Original file line number Diff line number Diff line change @@ -29,3 +29,8 @@ export const Store = Joi.object({
29
29
} ) ,
30
30
file,
31
31
} )
32
+
33
+ export const Search = Joi . object ( {
34
+ category : Joi . string ( ) . alphanum ( ) . required ( ) ,
35
+ filename : Joi . string ( ) . regex ( RegexSanitize ) . required ( ) ,
36
+ } )
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ class Images {
38
38
const Router = this . http . Router ( )
39
39
40
40
Router . post ( '/' , this . http . Upload ( 'file' ) , handler . Store ( ) )
41
+ Router . get ( '/' , handler . Search ( ) )
41
42
42
43
this . http . SetRouter ( '/v1/images' , Router )
43
44
}
Original file line number Diff line number Diff line change 1
1
import { readFileSync } from 'fs'
2
2
import { RequestParams } from '../../../helpers/requestParams'
3
3
import Logger from '../../../pkg/logger'
4
- import { File , Store } from '../entity/interface'
4
+ import { File , Search , Store } from '../entity/interface'
5
5
import Repository from '../repository/mongo/repository'
6
6
import S3 from '../../../external/s3'
7
7
import { CustomPathFile } from '../../../helpers/file'
@@ -11,6 +11,8 @@ import {
11
11
RegexExtensionImage ,
12
12
} from '../../../helpers/regex'
13
13
import FileGenerator from '../../../external/fileGenerator'
14
+ import statusCode from '../../../pkg/statusCode'
15
+ import error from '../../../pkg/error'
14
16
15
17
class Usecase {
16
18
constructor (
@@ -93,6 +95,13 @@ class Usecase {
93
95
this . logger . Error ( error . message )
94
96
}
95
97
}
98
+
99
+ public async Search ( { filename, category } : Search ) {
100
+ const path = `${ category } /${ filename } `
101
+ const result = await this . repository . FindByPath ( path )
102
+
103
+ return ! ! result
104
+ }
96
105
}
97
106
98
107
export default Usecase
You can’t perform that action at this time.
0 commit comments