Download spectrum/api/models/communitySettings.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/models/communitySettings.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/models/communitySettings.js
-
curl -L -o communitySettings.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/models/communitySettings.js
2.22 kB
| // @flow | |
| const { db } = require('shared/db'); | |
| import type { DBCommunitySettings } from 'shared/types'; | |
| const defaultSettings = { | |
| brandedLogin: { | |
| isEnabled: false, | |
| message: null, | |
| }, | |
| slackSettings: { | |
| connectedAt: null, | |
| connectedBy: null, | |
| teamName: null, | |
| teamId: null, | |
| scope: null, | |
| token: null, | |
| invitesSentAt: null, | |
| invitesMemberCount: null, | |
| invitesCustomMessage: null, | |
| }, | |
| joinSettings: { | |
| tokenJoinEnabled: false, | |
| token: null, | |
| }, | |
| }; | |
| // prettier-ignore | |
| export const getCommunitySettings = (id: string): Promise<DBCommunitySettings> => { | |
| return db | |
| .table('communitySettings') | |
| .getAll(id, { index: 'communityId' }) | |
| .run() | |
| .then(data => { | |
| if (!data || data.length === 0) { | |
| return defaultSettings; | |
| } | |
| return data[0]; | |
| }); | |
| }; | |
| // prettier-ignore | |
| export const getCommunitiesSettings = (communityIds: Array<string>): Promise<?DBCommunitySettings> => { | |
| return db | |
| .table('communitySettings') | |
| .getAll(...communityIds, { index: 'communityId' }) | |
| .run() | |
| .then(data => { | |
| if (!data || data.length === 0) { | |
| return Array.from({ length: communityIds.length }, (_, index) => ({ | |
| ...defaultSettings, | |
| communityId: communityIds[index], | |
| })); | |
| } | |
| if (data.length === communityIds.length) { | |
| return data.map( | |
| (rec, index) => | |
| rec | |
| ? rec | |
| : { | |
| ...defaultSettings, | |
| communityId: communityIds[index], | |
| } | |
| ); | |
| } | |
| if (data.length < communityIds.length) { | |
| return communityIds.map(communityId => { | |
| const record = data.find(o => o.communityId === communityId); | |
| if (record) return record; | |
| return { | |
| ...defaultSettings, | |
| communityId, | |
| }; | |
| }); | |
| } | |
| if (data.length > communityIds.length) { | |
| return communityIds.map(communityId => { | |
| const record = data.find(o => o.communityId === communityId); | |
| if (record) return record; | |
| return { | |
| ...defaultSettings, | |
| communityId, | |
| }; | |
| }); | |
| } | |
| }); | |
| }; | |