Skip to content

Commit 6bc3b06

Browse files
committed
feat(keystone): DOMA-10804 some fixes
1 parent 77e8e81 commit 6bc3b06

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

packages/keystone/fields/CloudStorageText/Implementation.js

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ class CloudStorageTextImplementation extends Text.implementation {
77
super(...arguments)
88
this.fileAdapter = adapter
99
this.isMultiline = true
10+
this.isOrderable = false
11+
}
12+
equalityInputFields () {
13+
return []
14+
}
15+
equalityInputFieldsInsensitive () {
16+
return []
17+
}
18+
inInputFields () {
19+
return []
20+
}
21+
orderingInputFields () {
22+
return []
23+
}
24+
stringInputFields () {
25+
return []
26+
}
27+
stringInputFieldsInsensitive () {
28+
return []
1029
}
1130
}
1231

packages/keystone/fields/CloudStorageText/adapters/index.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const { Text } = require('@keystonejs/fields')
22
const cuid = require('cuid')
3-
const isNil = require('lodash/isNil')
43

4+
const { CLOUD_STORAGE_TEXT_MIMETYPE, CLOUD_STORAGE_TEXT_ENCODING } = require('@open-condo/keystone/fields/CloudStorageText/constants')
55
const { bufferToStream, readFileFromStream, getObjectStream } = require('@open-condo/keystone/file')
66

7+
78
const CommonInterface = superclass => class extends superclass {
89

910
constructor () {
@@ -16,7 +17,7 @@ const CommonInterface = superclass => class extends superclass {
1617

1718
setupHooks ({ addPreSaveHook, addPostReadHook }) {
1819
addPreSaveHook(async (item) => {
19-
if (this._isFieldDefined(item)) {
20+
if (item[this.path]) {
2021
item[this.path] = await this._saveFileToAdapter(item[this.path])
2122
}
2223
return item
@@ -30,30 +31,24 @@ const CommonInterface = superclass => class extends superclass {
3031
})
3132
}
3233

33-
_isFieldDefined (item) {
34-
return item && !isNil(item[this.path])
35-
}
36-
3734
async _saveFileToAdapter (content) {
3835
const stream = bufferToStream(content)
39-
const originalFilename = this._generateFilename()
40-
const mimetype = 'text/plain'
41-
const encoding = 'utf8'
36+
const originalFilename = cuid()
4237

4338
const { id, filename, _meta } = await this.fileAdapter.save({
4439
stream,
4540
filename: originalFilename,
46-
mimetype,
47-
encoding,
41+
mimetype: CLOUD_STORAGE_TEXT_MIMETYPE,
42+
encoding: CLOUD_STORAGE_TEXT_ENCODING,
4843
id: cuid(),
4944
})
5045

5146
return {
5247
id,
5348
filename,
5449
originalFilename,
55-
mimetype,
56-
encoding,
50+
mimetype: CLOUD_STORAGE_TEXT_MIMETYPE,
51+
encoding: CLOUD_STORAGE_TEXT_ENCODING,
5752
_meta,
5853
}
5954
}
@@ -64,12 +59,10 @@ const CommonInterface = superclass => class extends superclass {
6459
return fileContent.toString()
6560
}
6661

67-
_generateFilename () {
68-
return `${new Date().toISOString()}`
69-
}
70-
7162
addToTableSchema (table) {
72-
table.jsonb(this.path)
63+
const column = table.jsonb(this.path)
64+
if (this.isNotNullable) column.notNullable()
65+
if (this.defaultTo) column.defaultTo(this.defaultTo)
7366
}
7467
}
7568

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const CLOUD_STORAGE_TEXT_MIMETYPE = 'text/plain'
2+
const CLOUD_STORAGE_TEXT_ENCODING = 'utf8'
3+
4+
module.exports = {
5+
CLOUD_STORAGE_TEXT_MIMETYPE,
6+
CLOUD_STORAGE_TEXT_ENCODING,
7+
}

0 commit comments

Comments
 (0)