synt_backend
Version:
Synt light-weight node backend service
30 lines (22 loc) • 659 B
JavaScript
import db from "../mysql/models";
import { upsertTranslationsDB } from "./translations";
export async function upsertLabelDB(labelId) {
let label = labelId
? await db.Label.findOne({ where: { id: labelId } })
: null;
if (!label) {
label = await db.Label.create();
}
return label;
}
/**
* translations has shape of { value: string; language: string; id: number }[];
*/
export async function upsertTranslatedLabelDB({ translations, labelId }) {
if (translations.length === 0) {
return null;
}
const label = await upsertLabelDB(labelId);
await upsertTranslationsDB({ translations, labelId: label.id });
return label;
}