288 lines
6.6 KiB
TypeScript
288 lines
6.6 KiB
TypeScript
import type { PayloadRequest } from 'payload/types';
|
|
|
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults';
|
|
import { LocalizedArrays } from './collections/LocalizedArrays';
|
|
import { LocalizedBlocks } from './collections/LocalizedBlocks';
|
|
import { LocalizedGroups } from './collections/LocalizedGroups';
|
|
import { Pages } from './collections/Pages';
|
|
import { People } from './collections/People';
|
|
import { Posts } from './collections/Posts';
|
|
import { MainMenu } from './globals/MainMenu';
|
|
|
|
const config = buildConfigWithDefaults({
|
|
collections: [
|
|
LocalizedArrays,
|
|
LocalizedBlocks,
|
|
LocalizedGroups,
|
|
Pages,
|
|
People,
|
|
Posts,
|
|
],
|
|
globals: [
|
|
MainMenu,
|
|
],
|
|
localization: {
|
|
locales: ['en', 'es'],
|
|
defaultLocale: 'en',
|
|
},
|
|
onInit: async (payload) => {
|
|
// await payload.create({
|
|
// collection: 'users',
|
|
// data: {
|
|
// email: devUser.email,
|
|
// password: devUser.password,
|
|
// },
|
|
// });
|
|
const req = {} as PayloadRequest;
|
|
|
|
req.transactionID = await payload.db.beginTransaction();
|
|
|
|
const page1 = await payload.create({
|
|
req,
|
|
collection: 'pages',
|
|
data: {
|
|
slug: 'first',
|
|
},
|
|
})
|
|
|
|
const page2 = await payload.create({
|
|
req,
|
|
collection: 'pages',
|
|
data: {
|
|
slug: 'second',
|
|
},
|
|
})
|
|
|
|
await payload.db.commitTransaction(req.transactionID);
|
|
|
|
|
|
const findResult = await payload.find({
|
|
collection: 'pages',
|
|
where: { slug: { equals: 'second' } },
|
|
})
|
|
|
|
const findOneResult = await payload.findByID({
|
|
collection: 'pages',
|
|
id: page1.id,
|
|
})
|
|
|
|
const person1 = await payload.create({
|
|
collection: 'people',
|
|
data: {
|
|
fullName: 'Dan Ribbens',
|
|
},
|
|
})
|
|
|
|
req.transactionID = await payload.db.beginTransaction();
|
|
|
|
const person2 = await payload.create({
|
|
req,
|
|
collection: 'people',
|
|
data: {
|
|
fullName: 'Elliot DeNolf',
|
|
},
|
|
})
|
|
|
|
const post = await payload.create({
|
|
req,
|
|
collection: 'posts',
|
|
data: {
|
|
throw: true,
|
|
title: 'hello',
|
|
number: 1337,
|
|
myGroup: {
|
|
subField: 'hello',
|
|
subFieldLocalized: 'hello in english',
|
|
subGroup: {
|
|
subSubField: 'sub hello',
|
|
subSubFieldLocalized: 'sub hello in english',
|
|
},
|
|
groupArray: [
|
|
{
|
|
groupArrayText: 'hello 1',
|
|
},
|
|
{
|
|
groupArrayText: 'hello 2',
|
|
},
|
|
],
|
|
},
|
|
relationHasOne: page1.id,
|
|
relationHasOnePoly: {
|
|
relationTo: 'people',
|
|
value: person1.id,
|
|
},
|
|
relationHasMany: [page1.id, page2.id],
|
|
relationHasManyPoly: [
|
|
{
|
|
relationTo: 'people',
|
|
value: person1.id,
|
|
},
|
|
{
|
|
relationTo: 'pages',
|
|
value: page2.id,
|
|
},
|
|
],
|
|
myArray: [
|
|
{
|
|
subField: 'hello 1',
|
|
mySubArray: [
|
|
{
|
|
subSubField: 'row 1 subrow 1',
|
|
},
|
|
{
|
|
subSubField: 'row 1 subrow 2',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
subField: 'hello 2',
|
|
mySubArray: [
|
|
{
|
|
subSubField: 'row 2 subrow 1',
|
|
},
|
|
{
|
|
subSubField: 'row 2 subrow 2',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
myBlocks: [
|
|
{
|
|
blockType: 'block1',
|
|
nonLocalizedText: 'hello',
|
|
localizedText: 'hello in english',
|
|
},
|
|
{
|
|
blockType: 'block2',
|
|
number: 123,
|
|
blockArray: [
|
|
{
|
|
subBlockArray: 'row 1',
|
|
},
|
|
{
|
|
subBlockArray: 'row 2',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
})
|
|
await payload.db.commitTransaction(req.transactionID);
|
|
await payload.update({
|
|
collection: 'posts',
|
|
id: post.id,
|
|
data: {
|
|
title: 'hello 2',
|
|
number: 1338,
|
|
myGroup: {
|
|
subFieldLocalized: 'hello in english updated',
|
|
subGroup: {
|
|
subSubField: 'sub hello updated',
|
|
subSubFieldLocalized: 'sub hello in english updated',
|
|
},
|
|
groupArray: [
|
|
{
|
|
groupArrayText: 'hello 1 updated',
|
|
},
|
|
{
|
|
groupArrayText: 'hello 2 updated',
|
|
},
|
|
],
|
|
},
|
|
relationHasOne: page2.id,
|
|
relationHasOnePoly: {
|
|
relationTo: 'people',
|
|
value: person2.id,
|
|
},
|
|
relationHasMany: [page2.id, page1.id],
|
|
relationHasManyPoly: [
|
|
{
|
|
relationTo: 'pages',
|
|
value: page2.id,
|
|
},
|
|
{
|
|
relationTo: 'people',
|
|
value: person1.id,
|
|
},
|
|
],
|
|
myArray: [
|
|
{
|
|
subField: 'hello 1 updated',
|
|
mySubArray: [
|
|
{
|
|
subSubField: 'row 1 subrow 1 updated',
|
|
},
|
|
{
|
|
subSubField: 'row 1 subrow 2 updated',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
subField: 'hello 2 updated',
|
|
mySubArray: [
|
|
{
|
|
subSubField: 'row 2 subrow 1 updated',
|
|
},
|
|
{
|
|
subSubField: 'row 2 subrow 2 updated',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
myBlocks: [
|
|
{
|
|
blockType: 'block1',
|
|
nonLocalizedText: 'hello updated',
|
|
localizedText: 'hello in english updated',
|
|
},
|
|
{
|
|
blockType: 'block2',
|
|
number: 1234,
|
|
blockArray: [
|
|
{
|
|
subBlockArray: 'row 1 updated',
|
|
},
|
|
{
|
|
subBlockArray: 'row 2 updated',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
const text = 'block';
|
|
const blockDoc = await payload.create({
|
|
collection: 'localized-blocks',
|
|
data: {
|
|
title: 'titled',
|
|
layout: [{
|
|
blockType: 'text',
|
|
text,
|
|
}],
|
|
}
|
|
})
|
|
|
|
const nope = await payload.create({
|
|
collection: 'localized-blocks',
|
|
data: {
|
|
title: 'titled',
|
|
layout: [{
|
|
blockType: 'text',
|
|
text: 'should not be found',
|
|
}],
|
|
}
|
|
})
|
|
|
|
const query = await payload.find({
|
|
collection: 'localized-blocks',
|
|
where: {
|
|
'layout.text': { equals: text }
|
|
}
|
|
})
|
|
|
|
console.log({ query });
|
|
},
|
|
})
|
|
|
|
export default config
|