Created
November 26, 2022 20:27
-
-
Save harazdovskiy/a3cadf86be3ff3cf3f18dc9703e27420 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {ulid} = require('ulid'); | |
const {client, index} = require("../elastic.js"); | |
module.exports.createHandler = async (request, h) => { | |
if (Object.keys(request.payload)) | |
try { | |
const res = await this.create(request.payload) | |
return h.response(res).code(200); | |
} catch (e) { | |
console.log({e}) | |
return h.response({e}).code(400); | |
} | |
} | |
module.exports.create = async (entity) => { | |
const { | |
type, | |
value, | |
name, | |
} = entity; | |
const document = { | |
id: ulid(), | |
type: type.trim().toLowerCase(), | |
value: +value.toFixed(0), | |
name: name.trim() | |
} | |
await client.index({ | |
index, | |
document | |
}); | |
return document.id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment