first commit

This commit is contained in:
2025-04-22 10:56:56 +07:00
commit af123c091b
147 changed files with 778063 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const cities = await prisma.addressCities.findMany({
where: {
Parent: parent.Code,
},
})
return cities.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch cities' },
}
}
})

View File

@@ -0,0 +1,31 @@
import { useToNumber, useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const limit = useToNumber(useToString(query.limit).value).value || 5
const search = useToString(query.search)
try {
const countries = await prisma.addressCountries.findMany({
// where: {
// Name: {
// startsWith: search.value,
// mode: 'insensitive',
// },
// },
// take: limit,
})
return countries.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch countries' },
}
}
})

View File

@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const districts = await prisma.addressDistricts.findMany({
where: {
Parent: parent.Code,
},
})
return districts.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch districts' },
}
}
})

View File

@@ -0,0 +1,181 @@
import { useFuse } from '@vueuse/integrations/useFuse'
import { useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const keywords = useToString(query.search).value.split(' ')
const nameSearch = keywords.map((word) => {
return { Name: { startsWith: word, mode: 'insensitive' } }
})
try {
const villages = await prisma.addressVillages.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
District: {
select: {
Name: true,
City: {
select: {
Name: true,
State: {
select: {
Name: true,
Country: {
select: {
Name: true,
},
},
},
},
},
},
},
},
},
take: 100,
})
const districts = await prisma.addressDistricts.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
City: {
select: {
Name: true,
State: {
select: {
Name: true,
Country: {
select: {
Name: true,
},
},
},
},
},
},
},
take: 50,
})
const cities = await prisma.addressCities.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
State: {
select: {
Name: true,
Country: {
select: {
Name: true,
},
},
},
},
},
take: 30,
})
const states = await prisma.addressStates.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
Country: {
select: {
Name: true,
},
},
},
take: 20,
})
const countries = await prisma.addressCountries.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
},
take: 10,
})
const addresses = [
...villages.map((item) => {
return {
villages: item.Name,
districts: item.District?.Name,
cities: item.District?.City?.Name,
states: item.District?.City?.State?.Name,
countries: item.District?.City?.State?.Country?.Name,
postal: item.Postal,
}
}),
...districts.map((item) => {
return {
districts: item.Name,
cities: item.City?.Name,
states: item.City?.State?.Name,
countries: item.City?.State?.Country?.Name,
postal: item.Postal,
}
}),
...cities.map((item) => {
return {
cities: item.Name,
states: item.State?.Name,
countries: item.State?.Country?.Name,
postal: item.Postal,
}
}),
...states.map((item) => {
return {
states: item.Name,
countries: item.Country?.Name,
postal: item.Postal,
}
}),
...countries.map((item) => {
return {
countries: item.Name,
postal: item.Postal,
}
}),
]
const options = {
fuseOptions: {
keys: ['villages', 'districts', 'cities', 'states', 'countries'],
shouldSort: true,
// includeScore: true,
minMatchCharLength: 3,
threshold: 0.8,
},
}
const { results } = useFuse(useToString(query.search), addresses, options)
return results.value
.map((value) => {
return value.item
})
.slice(0, 9)
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch addresses' },
}
}
})

View File

@@ -0,0 +1,19 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const districts = await prisma.addressDistricts.findUnique({
where: {
Code: parent.Code,
},
})
return districts.Postal
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch districts' },
}
}
})

View File

@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const states = await prisma.addressStates.findMany({
where: {
Parent: parent.Code,
},
})
return states.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch states' },
}
}
})

View File

@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const villages = await prisma.addressVillages.findMany({
where: {
Parent: parent.Code,
},
})
return villages.map((c) => {
return {
Code: '' + c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch villages' },
}
}
})

View File

@@ -0,0 +1,32 @@
import { useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const results = await prisma.address.aggregateRaw({
pipeline: [
{ $unwind: { path: '$regencies' } },
{
$match: {
_id: parent._id,
},
},
{
$project: {
_id: '$regencies._id',
name: '$regencies.name',
},
},
],
})
return results
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch regencies' },
}
}
})

View File

@@ -0,0 +1,22 @@
import { useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const search = useToString(query.search)
try {
const results = await prisma.country.findMany()
return results.map((r) => {
return {
_id: r.id,
name: r.name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch countries' },
}
}
})

View File

@@ -0,0 +1,33 @@
import { useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const results = await prisma.address.aggregateRaw({
pipeline: [
{ $unwind: { path: '$regencies' } },
{ $unwind: { path: '$regencies.districts' } },
{
$match: {
'regencies._id': parent._id,
},
},
{
$project: {
_id: '$regencies.districts._id',
name: '$regencies.districts.name',
},
},
],
})
return results
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch districts' },
}
}
})

View File

@@ -0,0 +1,93 @@
import { useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const keywords = useToString(query.search).value.split(' ')
function pipelineFilter(keywords) {
var result = [{}]
keywords.forEach((keyword, index) => {
result[index] = {
$match: {
$or: [
{
'regencies.districts.villages.name': {
$regex: (index === 0 ? '^' : '') + keyword,
$options: 'i',
},
},
{
'regencies.districts.name': {
$regex: (index === 0 ? '^' : '') + keyword,
$options: 'i',
},
},
{
'regencies.name': {
$regex: (index === 0 ? '^(KOTA|KABUPATEN) ' : '') + keyword,
$options: 'i',
},
},
{
name: {
$regex: (index === 0 ? '^' : '') + keyword,
$options: 'i',
},
},
],
},
}
})
return result
}
try {
const results = await prisma.address.aggregateRaw({
pipeline: [
{ $unwind: { path: '$regencies' } },
{ $unwind: { path: '$regencies.districts' } },
{
$unwind: {
path: '$regencies.districts.villages',
},
},
...pipelineFilter(keywords),
{
$limit: 10,
},
{
$project: {
_id: 1,
name: 1,
regencies: {
_id: 1,
name: 1,
districts: {
_id: 1,
name: 1,
villages: {
_id: 1,
name: 1,
},
},
},
},
},
],
})
return results.map((result) => {
return {
_id: 'ID',
name: 'INDONESIA',
states: result,
display: `DESA/KEL ${result.regencies.districts.villages.name} KEC. ${result.regencies.districts.name} ${result.regencies.name} PROVINSI ${result.name}`,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch address' },
}
}
})

View File

@@ -0,0 +1,19 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const results = await prisma.postal.findFirst({
where: {
id: parseInt(parent._id),
},
})
return results.postal
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch postal' },
}
}
})

View File

@@ -0,0 +1,29 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
if (parent._id !== 'ID') {
return {}
}
try {
const results = await prisma.address.findMany({
select: {
id: true,
name: true,
},
})
return results.map((r) => {
return {
_id: r.id,
name: r.name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch states' },
}
}
})

View File

@@ -0,0 +1,34 @@
import { useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const results = await prisma.address.aggregateRaw({
pipeline: [
{ $unwind: { path: '$regencies' } },
{ $unwind: { path: '$regencies.districts' } },
{ $unwind: { path: '$regencies.districts.villages' } },
{
$match: {
'regencies.districts._id': parent._id,
},
},
{
$project: {
_id: '$regencies.districts.villages._id',
name: '$regencies.districts.villages.name',
},
},
],
})
return results
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch villages' },
}
}
})

58
server/api/auth/[...].ts Normal file
View File

@@ -0,0 +1,58 @@
// import CredentialsProvider from 'next-auth/providers/credentials'
import KeycloakProvider from 'next-auth/providers/keycloak'
import { NuxtAuthHandler } from '#auth'
export default NuxtAuthHandler({
// TODO: SET A STRONG SECRET, SEE https://sidebase.io/nuxt-auth/configuration/nuxt-auth-handler#secret
secret: process.env.AUTH_SECRET || '32HslhZ8Hn97SsbxcmowhXvmNZ9cPGNE',
// TODO: ADD YOUR OWN AUTHENTICATION PROVIDER HERE, READ THE DOCS FOR MORE: https://sidebase.io/nuxt-auth
providers: [
// @ts-expect-error You need to use .default here for it to work during SSR. May be fixed via Vite at some point
KeycloakProvider.default({
clientId: process.env.KEYCLOAK_ID,
clientSecret: process.env.KEYCLOAK_SECRET,
issuer: process.env.KEYCLOAK_ISSUER,
}),
// // @ts-expect-error You need to use .default here for it to work during SSR. May be fixed via Vite at some point
// CredentialsProvider.default({
// // The name to display on the sign in form (e.g. 'Sign in with...')
// name: 'Credentials',
// // The credentials is used to generate a suitable form on the sign in page.
// // You can specify whatever fields you are expecting to be submitted.
// // e.g. domain, username, password, 2FA token, etc.
// // You can pass any HTML attribute to the <input> tag through the object.
// credentials: {
// username: { label: 'Username', type: 'text', placeholder: '(hint: jsmith)' },
// password: { label: 'Password', type: 'password', placeholder: '(hint: hunter2)' }
// },
// authorize (credentials: any) {
// console.warn('ATTENTION: You should replace this with your real providers or credential provider logic! The current setup is not safe')
// // You need to provide your own logic here that takes the credentials
// // submitted and returns either a object representing a user or value
// // that is false/null if the credentials are invalid.
// // NOTE: THE BELOW LOGIC IS NOT SAFE OR PROPER FOR AUTHENTICATION!
// const user = { id: '1', name: 'J Smith', username: 'jsmith', password: 'hunter2' }
// if (credentials?.username === user.username && credentials?.password === user.password) {
// // Any object returned will be saved in `user` property of the JWT
// return user
// } else {
// console.error('Warning: Malicious login attempt registered, bad credentials provided')
// // If you return null then an error will be displayed advising the user to check their details.
// return null
// // You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
// }
// }
// })
],
pages: {
signIn: '/auth/login',
// signOut: '/auth/signOut',
// error: '/auth/error',
// verifyRequest: '/auth/verify-request',
// newUser: '/auth/new-user'
},
})

View File

@@ -0,0 +1,12 @@
// import dataJson from './basic/data.json'
import fs from 'fs'
export default eventHandler(async (event) => {
const token = event.context.auth.token
if (!token) return {status: 'unauthenticated'}
const type = getRouterParam(event, 'type')
const data = getRouterParam(event, 'data')
const jsonString = fs.readFileSync('/home/kanzi/node/nuxt/vitify-nuxt/server/api/forms/json/'+type+'/'+data+'.json', 'utf-8');
return jsonString
})

View File

@@ -0,0 +1,9 @@
{
"name": "John Doe",
"vegetarian": false,
"birthDate": "1985-06-02",
"personalData": {
"age": 34
},
"postalCode": "12345"
}

View File

@@ -0,0 +1,126 @@
{
"en": {
"name": {
"label": "Name",
"description": "The name of the person"
},
"vegetarian": {
"label": "Vegetarian",
"description": "Whether the person is a vegetarian"
},
"birth": {
"label": "Birth Date",
"description": ""
},
"nationality": {
"label": "Nationality",
"description": ""
},
"personal-data": {
"age": {
"label": "Age"
},
"driving": {
"label": "Driving Skill",
"description": "Indicating experience level"
}
},
"height": {
"label": "Height"
},
"occupation": {
"label": "Occupation",
"description": ""
},
"postal-code": {
"label": "Postal Code"
},
"error": {
"required": "field is required"
}
},
"de": {
"name": {
"label": "Name",
"description": "Der Name der Person"
},
"vegetarian": {
"label": "Vegetarier",
"description": "Isst die Person vegetarisch?"
},
"birth": {
"label": "Geburtsdatum",
"description": ""
},
"nationality": {
"label": "Nationalität",
"description": "",
"Other": "Andere"
},
"personal-data": {
"age": {
"label": "Alter"
},
"driving": {
"label": "Fahrkenntnisse",
"description": "Fahrerfahrung der Person"
}
},
"height": {
"label": "Größe"
},
"occupation": {
"label": "Beruf",
"description": ""
},
"postal-code": {
"label": "Postleitzahl"
},
"error": {
"required": "Pflichtfeld"
},
"Additional Information": "Zusätzliche Informationen"
},
"bg": {
"name": {
"label": "Име",
"description": "Името на лицето"
},
"vegetarian": {
"label": "Вегетарианец",
"description": "Дали човекът е вегетарианец"
},
"birth": {
"label": "Рождена дата",
"description": ""
},
"nationality": {
"label": "Националност",
"description": ""
},
"personal-data": {
"age": {
"label": "Възраст",
"description": "Моля, въведете вашата възраст."
},
"driving": {
"label": "Шофьорски умения",
"description": "Показва ниво на опит"
}
},
"height": {
"label": "Височина"
},
"occupation": {
"label": "Професия",
"description": ""
},
"postal-code": {
"label": "Пощенски код"
},
"error": {
"required": "полето е задължително"
},
"Additional Information": "Допълнителна информация"
}
}

View File

@@ -0,0 +1,57 @@
{
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 3,
"description": "Please enter your name",
"i18n": "name"
},
"vegetarian": {
"type": "boolean",
"i18n": "vegetarian"
},
"birthDate": {
"type": "string",
"format": "date",
"i18n": "birth"
},
"nationality": {
"type": "string",
"enum": ["DE", "IT", "JP", "US", "RU", "Other"],
"i18n": "nationality"
},
"personalData": {
"type": "object",
"properties": {
"age": {
"type": "integer",
"description": "Please enter your age.",
"i18n": "personal-data.age"
},
"height": {
"type": "number",
"i18n": "height"
},
"drivingSkill": {
"type": "number",
"maximum": 10,
"minimum": 1,
"default": 7,
"i18n": "personal-data.driving"
}
},
"required": ["age", "height"]
},
"occupation": {
"type": "string",
"i18n": "occupation"
},
"postalCode": {
"type": "string",
"maxLength": 5,
"i18n": "postal-code"
}
},
"required": ["occupation", "nationality"]
}

View File

@@ -0,0 +1,55 @@
{
"type": "VerticalLayout",
"elements": [
{
"type": "HorizontalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/name"
},
{
"type": "Control",
"scope": "#/properties/personalData/properties/age"
},
{
"type": "Control",
"scope": "#/properties/birthDate"
}
]
},
{
"type": "Label",
"text": "Additional Information"
},
{
"type": "HorizontalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/personalData/properties/height"
},
{
"type": "Control",
"scope": "#/properties/nationality"
},
{
"type": "Control",
"scope": "#/properties/occupation",
"options": {
"suggestion": [
"Accountant",
"Engineer",
"Freelancer",
"Journalism",
"Physician",
"Student",
"Teacher",
"Other"
]
}
}
]
}
]
}

View File

@@ -0,0 +1,33 @@
{
"properties": {
"name": {
"type": "string",
"minLength": 1,
"description": "The task's name"
},
"description": {
"title": "Long Description",
"type": "string"
},
"done": {
"type": "boolean"
},
"dueDate": {
"type": "string",
"format": "date",
"description": "The task's due date"
},
"rating": {
"type": "integer",
"maximum": 5
},
"recurrence": {
"type": "string",
"enum": ["Never", "Daily", "Weekly", "Monthly"]
},
"recurrenceInterval": {
"type": "integer",
"description": "Days until recurrence"
}
}
}

View File

@@ -0,0 +1,46 @@
{
"type": "HorizontalLayout",
"elements": [
{
"type": "VerticalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/name"
},
{
"type": "Control",
"scope": "#/properties/description",
"options": {
"multi": true
}
},
{
"type": "Control",
"scope": "#/properties/done"
}
]
},
{
"type": "VerticalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/dueDate"
},
{
"type": "Control",
"scope": "#/properties/rating"
},
{
"type": "Control",
"scope": "#/properties/recurrence"
},
{
"type": "Control",
"scope": "#/properties/recurrenceInterval"
}
]
}
]
}

View File

@@ -0,0 +1,57 @@
export default defineEventHandler(async (event) => {
const marital = {
'M': 'Menikah',
'U': 'Belum Menikah',
'jawa': 'Jawa',
'sunda': 'Sunda'
};
const body = await readBody(event)
const data = await prisma.patient.create({
data: {
active: body.active ? true : false,
identifier: body.identifier.map((i) => {
return {
name: i.name,
value: i.value,
}
}),
name: body.name.map((n) => ({
use: n.use || 'usual',
...(n.family && { family: n.family }),
...(n.given && { given: n.given }),
...(n.prefix && { prefix: n.prefix }),
...(n.suffix && { suffix: n.suffix }),
...(n.period &&
(n.period.start || n.period.end) && {
period: Object.fromEntries(
Object.entries({
start: n.period.start ? new Date(n.period.start) : undefined,
end: n.period.end ? new Date(n.period.end) : undefined,
}).filter(([, value]) => value !== undefined),
),
}),
})),
gender: body.gender,
birthDate: body.birthDate ? new Date(body.birthDate) : null,
birthPlace: body.birthPlace,
address: body.address,
maritalStatus: body.maritalStatus.map((m) => {
const coding = m.coding[0];
return {
preferred: coding.system ? true : false,
// coding: coding.system
code: coding.select,
display: marital[coding.select],
};
}),
communication: body.communication.map((c) => {
const language = c.language[0]
return {
preferred: c.preferred ? true : false,
language: [{ text: language.text }],
}
}),
},
})
return data
})

100
server/api/people.get.ts Normal file
View File

@@ -0,0 +1,100 @@
export default eventHandler(async (event) => {
await requireUserSession(event)
// List todos for the current user
const people = [
{
id: 1,
name: 'Lindsay Walton',
title: 'Front-end Developer',
email: 'lindsay.walton@example.com',
role: 'Member',
},
{
id: 2,
name: 'Courtney Henry',
title: 'Designer',
email: 'courtney.henry@example.com',
role: 'Admin',
},
{
id: 3,
name: 'Tom Cook',
title: 'Director of Product',
email: 'tom.cook@example.com',
role: 'Member',
},
{
id: 4,
name: 'Whitney Francis',
title: 'Copywriter',
email: 'whitney.francis@example.com',
role: 'Admin',
},
{
id: 5,
name: 'Leonard Krasner',
title: 'Senior Designer',
email: 'leonard.krasner@example.com',
role: 'Owner',
},
{
id: 6,
name: 'Floyd Miles',
title: 'Principal Designer',
email: 'floyd.miles@example.com',
role: 'Member',
},
{
id: 7,
name: 'Emily Selman',
title: 'VP, User Experience',
email: '',
role: 'Admin',
},
{
id: 8,
name: 'Kristin Watson',
title: 'VP, Human Resources',
email: '',
role: 'Member',
},
{
id: 9,
name: 'Emma Watson',
title: 'Front-end Developer',
email: '',
role: 'Member',
},
{
id: 10,
name: 'John Doe',
title: 'Designer',
email: '',
role: 'Admin',
},
{
id: 11,
name: 'Jane Doe',
title: 'Director of Product',
email: '',
role: 'Member',
},
{
id: 12,
name: 'John Smith',
title: 'Copywriter',
email: '',
role: 'Admin',
},
{
id: 13,
name: 'Jane Smith',
title: 'Senior Designer',
email: '',
role: 'Owner',
},
]
return people
})

View File

@@ -0,0 +1,42 @@
export default defineEventHandler(async (event) => {
const body = await readBody(event)
// return body
const data = await prisma.practitioner.create({
data: {
active: body.active ? true : false,
identifier: body.identifier.map((i) => {
return {
name: i.name,
value: i.value,
}
}),
name: body.name.map((n) => ({
use: n.use || 'usual',
...(n.family && { family: n.family }),
...(n.given && { given: n.given }),
...(n.prefix && { prefix: n.prefix }),
...(n.suffix && { suffix: n.suffix }),
...(n.period &&
(n.period.start || n.period.end) && {
period: Object.fromEntries(
Object.entries({
start: n.period.start ? new Date(n.period.start) : undefined,
end: n.period.end ? new Date(n.period.end) : undefined,
}).filter(([, value]) => value !== undefined),
),
}),
})),
gender: body.gender,
birthDate: body.birthDate ? new Date(body.birthDate) : null,
birthPlace: body.birthPlace,
address: body.address,
communication: body.communication.map((c) => {
return {
preferred: c.preferred ? true : false,
language: c.language,
}
}),
},
})
return data
})

View File

@@ -0,0 +1,65 @@
import { useToString } from '@vueuse/core'
import { take } from 'echarts/types/src/component/helper/interactionMutex.js'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const name = useToString(query.name).value.split(' ')
function pipelineFilter(keywords) {
var result = [{}]
keywords.forEach((keyword, index) => {
result[index] = {
$match: {
$or: [
{
'name.family': {
$regex: (index === 0 ? '^' : '') + keyword,
$options: 'i',
},
},
{
'name.given': {
$regex: (index === 0 ? '^' : '') + keyword,
$options: 'i',
},
},
],
},
}
})
return result
}
try {
if (Object.keys(query).length === 0) {
return await prisma.practitioner.aggregateRaw({
pipeline: [{ $limit: 100 }],
})
}
const practitioners = await prisma.practitioner.aggregateRaw({
pipeline: [
// { $unwind: { path: '$name.family' } },
...pipelineFilter(name),
{
$limit: 10,
},
// {
// $project: {
// id: 1,
// name: 1,
// },
// },
],
})
return practitioners
} catch (error) {
return {
status: 500,
body: {
messages: 'failed to fetch practitioners',
code: error,
},
}
}
})

View File

@@ -0,0 +1,3 @@
export default defineEventHandler((event) => ({
auth: event.context.auth ,
}));

View File

@@ -0,0 +1,10 @@
import { getServerSession, getToken } from '#auth'
export default eventHandler(async (event) => {
const session = await getServerSession(event)
if (!session) {
return { status: 'unauthenticated!' }
}
const token = await getToken({event})
return token || {status: 'no token present'}
})