dict.ts 545 B

12345678910111213141516171819202122232425
  1. import Dict, { DictCreationAttributes } from '../models/dict';
  2. export async function getDict(key: string) {
  3. const res = await Dict.findOne({
  4. where: { key },
  5. }).catch((err) => {
  6. console.dir(err);
  7. });
  8. return res ? res.dataValues.val : '';
  9. }
  10. export async function updateDict(data: DictCreationAttributes) {
  11. const dict = await Dict.findOne({
  12. where: { key: data.key },
  13. });
  14. if (dict) {
  15. dict.val = data.val;
  16. await dict.save();
  17. return dict;
  18. }
  19. const res = await Dict.create(data);
  20. return res.dataValues;
  21. }