Skip to content

Instantly share code, notes, and snippets.

View AlessioGr's full-sized avatar
🏔️

Alessio Gravili AlessioGr

🏔️
View GitHub Profile
@AlessioGr
AlessioGr / index.tsx
Created September 11, 2023 12:45
index.tsx
import type { FieldWithPath } from '../../../..'
import array from './Array'
import blocks from './Blocks'
import checkbox from './Checkbox'
import code from './Code'
import collapsible from './Collapsible'
import confirmPassword from './ConfirmPassword'
import date from './DateTime'
import email from './Email'
@AlessioGr
AlessioGr / simplifyWhereQuery.ts
Created July 26, 2023 21:04
simplifyWhereQuery.ts
import type { Where } from '../../../../types';
export const simplifyWhereQuery = (whereQuery: Where): Where => {
if (!whereQuery?.or) {
return whereQuery;
}
// Filter out {} values from 'or' array.
const orArray = whereQuery.or.filter((obj) => Object.keys(obj).length !== 0);
{
"_id":{
"$oid":"64b9b54c97eea491d64e5630"
},
"summary":"Be2 anmeldelse og test (2023) - Er Be2 en svindel?:",
"trigger_hooks":false,
"passthrough":{
"document_locale":"no-NO",
"niches":[
@AlessioGr
AlessioGr / PayloadCommunicator.ts
Last active March 12, 2023 12:34
Simple helper you can use to communicate with Payload CMS from your application via their REST API. Authorization via API key needs to be enabled in your users collection. More on enabling API keys here: https://payloadcms.com/docs/authentication/config#api-keys
import qs from 'qs';
export const cmsURL = "cms URL without the / at the end";
export const apiKey = "yourAPIkey";
export async function getDocuments (collectionName: string, whereQuery?) {
if (whereQuery) {
const stringifiedQuery = qs.stringify({
where: whereQuery
}, { addQueryPrefix: true });