import graphqlHelper from "../../lib/graphqlHelper"; type PasswordPolicy = "required" | "from_otp" | "disabled" graphqlHelper.addType(`#graphql type UserRestrictions { "Indicate main login field" loginField: String "Indicate required OTP on any login" loginOTPRequired: Boolean "List of all custom user fields" customFields: [UserCustomField] "Password is required in users accounts" passwordPolicy: String "Countries for send OTP" allowedPhoneCountries: [Country], linkToProcessingPersonalData: String, linkToUserAgreement: String "Allow spening bonuses" allowBonusSpending: Boolean "OTP code Length" OTPlength: Int } type Restrictions { "graphql scehma backward compatibility version" graphqlSchemaBackwardCompatibilityVersion: Int "Delivery service working time" worktime: Json "Time possible for order from now" possibleToOrderInMinutes: Int timezone: String "By default is POW" captchaType: String "Global delivery discription" deliveryDescription: Json "The minimum time for which delivery of the order is possible" minDeliveryTimeInMinutes: Int "Group User restrictions" user: UserRestrictions } `); export default { Query: { restrictions: { def: 'restrictions: Restrictions', fn: () => ({}) } }, Restrictions: { worktime: async () => await Settings.get('WORK_TIME'), graphqlSchemaBackwardCompatibilityVersion: () => 1, possibleToOrderInMinutes: async () => isNaN(parseInt(await Settings.get('POSSIBLE_TO_ORDER_IN_MINUTES') as string)) ? 7 * 24 * 60 : parseInt(await Settings.get('POSSIBLE_TO_ORDER_IN_MINUTES') as string), minDeliveryTimeInMinutes: async () => isNaN(parseInt(await Settings.get('MIN_DELIVERY_TIME_IN_MINUTES') as string)) ? 40 : parseInt(await Settings.get('MIN_DELIVERY_TIME_IN_MINUTES') as string), timezone: async () => { return await Settings.get('TZ') ?? 'Etc/GMT' }, captchaType: async () => await Settings.get('CAPTCHA_TYPE') || "POW", deliveryDescription: async () => await Settings.get('DELIVERY_DESCRIPTION'), user: () => ({}), // Dummy resolver to nest the fields below }, UserRestrictions: { loginField: async () => { let loginField = await Settings.get("LOGIN_FIELD"); return loginField || 'phone'; }, loginOTPRequired: async () => { let loginOTPRequired = await Settings.get("LOGIN_OTP_REQUIRED"); return loginOTPRequired || false; }, customFields: async () => { let customFields = await Settings.get("CUSTOM_FIELDS"); return customFields || []; }, passwordPolicy: async () => { let passwordPolicy = await Settings.get("PASSWORD_POLICY") as PasswordPolicy; return passwordPolicy || "from_otp"; }, allowedPhoneCountries: async () => { let allowedPhoneCountriesList = []; // ALLOWED_PHONE_COUNTRIES let allowedPhoneCountries = await Settings.get("ALLOWED_PHONE_COUNTRIES") as string | string[]; if (typeof allowedPhoneCountries === "string") allowedPhoneCountries = [allowedPhoneCountries]; if (Array.isArray(allowedPhoneCountries) && typeof allowedPhoneCountries[0] === "string") { allowedPhoneCountries.forEach(allowedPhoneCountry => { let country = sails.hooks.restocore.dictionaries.countries[allowedPhoneCountry] if (country) { allowedPhoneCountriesList.push(country) } }); } return allowedPhoneCountriesList; }, linkToProcessingPersonalData: () => "/static/processing_personal_data", linkToUserAgreement: () => "/static/user_agreement", OTPlength: () => 6, allowBonusSpending: async () => { return await Settings.get("ALLOW_BONUS_SPENDING") as boolean ?? true; }, } }