@things-factory/attachment-base 7.0.1-rc.8 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/attachment-base",
3
- "version": "7.0.1-rc.8",
3
+ "version": "7.0.1",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -29,11 +29,11 @@
29
29
  "@aws-sdk/s3-presigned-post": "^3.46.0",
30
30
  "@azure/storage-blob": "^12.18.0",
31
31
  "@koa/multer": "^3.0.0",
32
- "@things-factory/auth-base": "^7.0.1-rc.8",
33
- "@things-factory/env": "^7.0.1-rc.8",
34
- "@things-factory/shell": "^7.0.1-rc.8",
32
+ "@things-factory/auth-base": "^7.0.0",
33
+ "@things-factory/env": "^7.0.0",
34
+ "@things-factory/shell": "^7.0.0",
35
35
  "mime": "^3.0.0",
36
36
  "multer": "^1.4.5-lts.1"
37
37
  },
38
- "gitHead": "cf1d0f8f261c73eadecb517fc6c82e92e50d6caf"
38
+ "gitHead": "02f50498ba92589813db2d13907894d2b9220d8c"
39
39
  }
@@ -65,9 +65,10 @@ export class AttachmentMutation {
65
65
  @Mutation(returns => Boolean)
66
66
  async deleteAttachmentsByRef(
67
67
  @Arg('refBys', type => [String]) refBys: string[],
68
+ @Arg('refType', type => String, { nullable: true }) refType: string,
68
69
  @Ctx() context: ResolverContext
69
70
  ): Promise<boolean> {
70
- return await deleteAttachmentsByRef(null, { refBys }, context)
71
+ return await deleteAttachmentsByRef(null, { refBys, refType }, context)
71
72
  }
72
73
 
73
74
  @Directive('@transaction')
@@ -109,15 +110,17 @@ export class AttachmentMutation {
109
110
  export async function createAttachment(_: any, { attachment }, context: ResolverContext): Promise<Attachment> {
110
111
  const { file, category, refType = '', refBy, description } = attachment
111
112
  const { mimetype } = (await file) as FileUpload
112
-
113
- if(allowedMimeTypes instanceof Array && allowedMimeTypes.length > 0 && !allowedMimeTypes.includes('*/*')) {
113
+
114
+ if (allowedMimeTypes instanceof Array && allowedMimeTypes.length > 0 && !allowedMimeTypes.includes('*/*')) {
114
115
  const isAllowed = allowedMimeTypes.some(type => {
115
116
  const [typeMain, typeSub] = type.split('/')
116
117
  const [mimeMain, mimeSub] = mimetype.split('/')
117
- return (typeMain === mimeMain && (typeSub === '*' || typeSub === mimeSub)) || (typeMain === '*' && typeSub === '*')
118
+ return (
119
+ (typeMain === mimeMain && (typeSub === '*' || typeSub === mimeSub)) || (typeMain === '*' && typeSub === '*')
120
+ )
118
121
  })
119
122
 
120
- if(!isAllowed) {
123
+ if (!isAllowed) {
121
124
  throw Error(context.t(`error.not allowed file type for upload`, { mimetype }))
122
125
  }
123
126
  }
@@ -176,18 +179,32 @@ export async function deleteAttachment(_: any, { id }, context: ResolverContext)
176
179
  }
177
180
  }
178
181
 
179
- export async function deleteAttachmentsByRef(_: any, { refBys }, context: ResolverContext): Promise<boolean> {
182
+ interface DeleteAttachmentsObject {
183
+ refBys: Array<string>
184
+ refType?: string
185
+ }
186
+ export async function deleteAttachmentsByRef(
187
+ _: any,
188
+ { refBys, refType = null }: DeleteAttachmentsObject,
189
+ context: ResolverContext
190
+ ): Promise<boolean> {
180
191
  const { domain, tx } = context.state
181
-
182
192
  const repository = tx ? tx.getRepository(Attachment) : getRepository(Attachment)
193
+ const inquryWhereClause: any = { domain: { id: domain.id }, refBy: In(refBys) }
194
+ const deleteWhereClause: any = { refBy: In(refBys) }
195
+
196
+ // refType이 존재하면 where 절에 추가
197
+ if (refType) {
198
+ inquryWhereClause.refType = refType;
199
+ deleteWhereClause.refType = refType;
200
+ }
201
+
183
202
  const attachments = await repository.find({
184
- where: { domain: { id: domain.id }, refBy: In(refBys) }
203
+ where: inquryWhereClause
185
204
  })
186
205
 
187
206
  //remove attachment from repo
188
- await repository.delete({
189
- refBy: In(refBys)
190
- })
207
+ await repository.delete(deleteWhereClause)
191
208
 
192
209
  //remove files from attachments folder
193
210
  if (attachments.length) {