Skip to content

Instantly share code, notes, and snippets.

@harazdovskiy
Created November 26, 2022 20:27
Show Gist options
  • Save harazdovskiy/a3cadf86be3ff3cf3f18dc9703e27420 to your computer and use it in GitHub Desktop.
Save harazdovskiy/a3cadf86be3ff3cf3f18dc9703e27420 to your computer and use it in GitHub Desktop.
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