-
-
Save andreaskviby/73ae8a604e385da79d7e62c218bd1768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filename: backend/adminService.jsw (web modules need to have a .jsw extension) | |
import wixData from 'wix-data'; | |
//import {lookupValue} from 'backend/adminService'; | |
export function lookupValue(dataCollection, id) { | |
return wixData.query(dataCollection) | |
.eq("_id", id) | |
.limit(1) | |
.find() | |
.then((results) => { | |
if (results.totalCount > 0) { | |
return results.items[0].title; | |
} | |
return "empty"; | |
}) | |
} | |
//import {getAllRecords} from 'backend/adminService'; | |
export function getAllRecords(collectionName) { | |
return wixData.query(collectionName) | |
.find() | |
.then((results) => { | |
if (results.totalCount > 0) { | |
return results.items; | |
} else { | |
return null; | |
} | |
}) | |
} | |
//import {getAllRecordsIncludeOne} from 'backend/adminService'; | |
export function getAllRecordsIncludeOne(collectionName, includeCollection) { | |
return wixData.query(collectionName) | |
.include(includeCollection) | |
.find() | |
.then((results) => { | |
if (results.totalCount > 0) { | |
return results.items; | |
} else { | |
return null; | |
} | |
}) | |
} | |
//import {getAllRecordsIncludeTwo} from 'backend/adminService'; | |
export function getAllRecordsIncludeTwo(collectionName, includeCollection, includeAnotherCollection) { | |
return wixData.query(collectionName) | |
.include(includeCollection) | |
.include(includeAnotherCollection) | |
.find() | |
.then((results) => { | |
if (results.totalCount > 0) { | |
return results.items; | |
} else { | |
return null; | |
} | |
}) | |
} | |
//import {populateDropdown} from 'backend/adminService'; | |
export function populateDropdown(collectionName) { | |
let allItems = []; | |
return wixData.query(collectionName) | |
.find() | |
.then((results) => { | |
if (results.totalCount > 0) { | |
let items = results.items; | |
items.forEach((item) => { | |
let oneItem = { | |
label: item.title, | |
value: item._id | |
} | |
allItems.push(oneItem); | |
}) | |
return allItems; | |
} | |
return null; | |
}) | |
} | |
//import {populateDropdownWithAll} from 'backend/adminService'; | |
export function populateDropdownWithAll(collectionName) { | |
let allItems = []; | |
return wixData.query(collectionName) | |
.find() | |
.then((results) => { | |
if (results.totalCount > 0) { | |
let items = results.items; | |
items.forEach((item) => { | |
let oneItem = { | |
label: item.title, | |
value: item._id | |
} | |
allItems.push(oneItem); | |
}) | |
allItems.unshift({label: "All", value: "all"}); | |
return allItems; | |
} | |
return null; | |
}) | |
} | |
//import {populateDropdownWithFilter} from 'backend/adminService'; | |
export function populateDropdownWithFilter(collectionName,filterField,filterValue) { | |
let allItems = []; | |
return wixData.query(collectionName) | |
.eq(filterField,filterValue) | |
.find() | |
.then((results) => { | |
if (results.totalCount > 0) { | |
let items = results.items; | |
items.forEach((item) => { | |
let oneItem = { | |
label: item.title, | |
value: item._id | |
} | |
allItems.push(oneItem); | |
}) | |
allItems.unshift({label: "All", value: "all"}); | |
return allItems; | |
} | |
return null; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment