Files
payload/packages/db-postgres/src/findGlobal.ts

36 lines
711 B
TypeScript

import type { FindGlobal } from 'payload/database'
import toSnakeCase from 'to-snake-case'
import type { PostgresAdapter } from './types.js'
import { findMany } from './find/findMany.js'
export const findGlobal: FindGlobal = async function findGlobal(
this: PostgresAdapter,
{ locale, req, slug, where },
) {
const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)
const tableName = toSnakeCase(slug)
const {
docs: [doc],
} = await findMany({
adapter: this,
fields: globalConfig.fields,
limit: 1,
locale,
pagination: false,
req,
tableName,
where,
})
if (doc) {
doc.globalType = slug
return doc
}
return {}
}