| 1014 | |
| 1015 | // gets a pad safe |
| 1016 | const getPadSafe = async (padID: string|object, shouldExist: boolean, text?:string, authorId:string = '') => { |
| 1017 | // check if padID is a string |
| 1018 | if (typeof padID !== 'string') { |
| 1019 | throw new CustomError('padID is not a string', 'apierror'); |
| 1020 | } |
| 1021 | |
| 1022 | // check if the padID maches the requirements |
| 1023 | if (!padManager.isValidPadId(padID)) { |
| 1024 | throw new CustomError('padID did not match requirements', 'apierror'); |
| 1025 | } |
| 1026 | |
| 1027 | // check if the pad exists |
| 1028 | const exists = await padManager.doesPadExists(padID); |
| 1029 | |
| 1030 | if (!exists && shouldExist) { |
| 1031 | // does not exist, but should |
| 1032 | throw new CustomError('padID does not exist', 'apierror'); |
| 1033 | } |
| 1034 | |
| 1035 | if (exists && !shouldExist) { |
| 1036 | // does exist, but shouldn't |
| 1037 | throw new CustomError('padID does already exist', 'apierror'); |
| 1038 | } |
| 1039 | |
| 1040 | // pad exists, let's get it |
| 1041 | return padManager.getPad(padID, text, authorId); |
| 1042 | }; |
| 1043 | |
| 1044 | // checks if a padID is part of a group |
| 1045 | const checkGroupPad = (padID: string, field: string) => { |