Skip to content

Commit 7ff5334

Browse files
committed
DRY sanitizeRelationshipTypes
1 parent 8c67df1 commit 7ff5334

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

backend/src/graphql/resolvers/images/imagesLocal.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/require-await */
2-
/* eslint-disable @typescript-eslint/restrict-template-expressions */
2+
33
/* eslint-disable @typescript-eslint/no-unsafe-call */
44
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
55
/* eslint-disable @typescript-eslint/no-unsafe-return */
@@ -15,6 +15,7 @@ import { UserInputError } from 'apollo-server'
1515
import slug from 'slug'
1616
import { v4 as uuid } from 'uuid'
1717

18+
import { sanitizeRelationshipType } from './sanitizeRelationshipTypes'
1819
import { wrapTransaction } from './wrapTransaction'
1920

2021
import type { Images, FileDeleteCallback, FileUploadCallback } from './images'
@@ -116,14 +117,6 @@ const uploadImageFile = async (
116117
return uploadCallback({ createReadStream, uniqueFilename, mimetype })
117118
}
118119

119-
const sanitizeRelationshipType = (relationshipType) => {
120-
// Cypher query language does not allow to parameterize relationship types
121-
// See: https://github.com/neo4j/neo4j/issues/340
122-
if (!['HERO_IMAGE', 'AVATAR_IMAGE'].includes(relationshipType)) {
123-
throw new Error(`Unknown relationship type ${relationshipType}`)
124-
}
125-
}
126-
127120
const localFileUpload: FileUploadCallback = ({ createReadStream, uniqueFilename }) => {
128121
const destination = `/uploads/${uniqueFilename}`
129122
return new Promise((resolve, reject) =>

backend/src/graphql/resolvers/images/imagesS3.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { v4 as uuid } from 'uuid'
88

99
import { S3Configured } from '@config/index'
1010

11+
import { sanitizeRelationshipType } from './sanitizeRelationshipTypes'
1112
import { wrapTransaction } from './wrapTransaction'
1213

1314
import type { Image, Images, FileDeleteCallback, FileUploadCallback } from './images'
@@ -112,14 +113,6 @@ export const images = (config: S3Configured) => {
112113
return publicLocation.href
113114
}
114115

115-
const sanitizeRelationshipType = (relationshipType: string) => {
116-
// Cypher query language does not allow to parameterize relationship types
117-
// See: https://github.com/neo4j/neo4j/issues/340
118-
if (!['HERO_IMAGE', 'AVATAR_IMAGE'].includes(relationshipType)) {
119-
throw new Error(`Unknown relationship type ${relationshipType}`)
120-
}
121-
}
122-
123116
const s3Upload: FileUploadCallback = async ({ createReadStream, uniqueFilename, mimetype }) => {
124117
const s3Location = `original/${uniqueFilename}`
125118
const params = {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const sanitizeRelationshipType = (relationshipType: string) => {
2+
// Cypher query language does not allow to parameterize relationship types
3+
// See: https://github.com/neo4j/neo4j/issues/340
4+
if (!['HERO_IMAGE', 'AVATAR_IMAGE'].includes(relationshipType)) {
5+
throw new Error(`Unknown relationship type ${relationshipType}`)
6+
}
7+
}

0 commit comments

Comments
 (0)