settings.ts 861 Bytes
Newer Older
1
const handleChanges =
2
3
4
  ({ videoCategoryManager, logger }) =>
  (settings) => {
    try {
5
      logger.debug(settings['json-categories-as-text']);
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
      const jsonCategories = JSON.parse(settings['json-categories-as-text']);
      logger.debug(settings['json-categories-as-text']);
      if (jsonCategories.hasOwnProperty('add')) {
        const categoriesToAdd = jsonCategories['add'];
        categoriesToAdd.forEach(({ key, label }) =>
          videoCategoryManager.addCategory(key, label)
        );
      }

      if (jsonCategories.hasOwnProperty('delete')) {
        const categoriesToDelete = jsonCategories['delete'];
        categoriesToDelete.forEach((key) =>
          videoCategoryManager.deleteCategory(key)
        );
      }
    } catch (e) {
      logger.log({ level: 'error', message: e });
    }
  };

module.exports = {
27
  handleChanges,
28
};