Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JWebCoder committed Jul 24, 2024
1 parent 62b900a commit c5b3e87
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 24 deletions.
23 changes: 21 additions & 2 deletions src/models/files.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import { model } from '@funfunz/azure-blob-storage-connector/lib/index.js'
import { IEntityInfo, IProperty } from '@funfunz/core/lib/index.js';

const filesModel: any = model({
const filesModel: IEntityInfo = model({
name: 'files',
visible: true,
connector: 'azureBlobStorage'
});
}) as IEntityInfo

(filesModel.properties.find(p=>p.name==='content') as IProperty).backoffice = {
visible: {
entityPage: false
}
}

filesModel.relations = [
{
type: 'm:n',
relationalEntity: 'productsfiles',
foreignKey: 'name',
remoteEntity: 'products',
remoteForeignKey: 'productId',
}
]

filesModel.hooks = {
all: {
afterQueryResult: (data) => {
console.log(data.results)
return data
}
}
}

export default filesModel
9 changes: 3 additions & 6 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import rolesModel from './roles.js'
import usersModel from './users.js'
import usersrolesModel from './usersroles.js'
import filesModel from './files.js'
import productsFilesModel from './productsfiles.js'

const models = process.env.FUNFUNZ_CONNECTOR === 'json' ? [
const models = [
productsModel,
rolesModel,
usersModel,
usersrolesModel,
filesModel,
] : [
productsModel,
rolesModel,
usersModel,
usersrolesModel,
productsFilesModel,
]

export default models
18 changes: 13 additions & 5 deletions src/models/products.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IEntityInfo } from "@funfunz/core/lib/index.js"
import { checkPermissions } from "../hooks/permissions.js"

export default {
name: 'products',
connector: 'mainDatabase',
connector: 'jsonDatabase',
visible: true,
properties: [
{
Expand All @@ -14,7 +15,7 @@ export default {
}
},
{
name: 'name',
name: 'productName',
type: 'string',
backoffice: {
label: 'Name'
Expand All @@ -41,7 +42,7 @@ export default {
backoffice: {
label: 'User'
}
}
},
],
backoffice: {
label: 'Products',
Expand All @@ -51,11 +52,18 @@ export default {
type: 'n:1',
foreignKey: 'userId',
remoteEntity: 'users',
}
},
{
type: 'm:n',
relationalEntity: 'productsfiles',
foreignKey: 'productId',
remoteEntity: 'files',
remoteForeignKey: 'name',
},
],
hooks: {
all: {
beforeResolver: checkPermissions
}
}
}
} as IEntityInfo
38 changes: 38 additions & 0 deletions src/models/productsfiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { checkPermissions } from '../hooks/permissions.js'

export default {
name: 'productsfiles',
connector: 'jsonDatabase',
visible: true,
properties: [
{
name: 'productId',
type: 'number',
isPk: true
},
{
name: 'name',
type: 'string',
isPk: true
}
],
relations: [
{
type: 'n:1',
relationalEntity: 'productsfiles',
foreignKey: 'productId',
remoteEntity: 'products'
},
{
type: 'n:1',
relationalEntity: 'productsfiles',
foreignKey: 'name',
remoteEntity: 'files'
}
],
hooks: {
all: {
beforeResolver: checkPermissions
}
}
}
15 changes: 7 additions & 8 deletions src/setup/funfunz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import models from '../models/index.js'
import mutations from '../graphql/mutations/index.js'
import queries from '../graphql/queries/index.js'
import { Connector as blobStorageConnector } from '@funfunz/azure-blob-storage-connector'
import { Connector as sqlDataConnector} from '@funfunz/sql-data-connector'
import { Connector as jsonDataConnector} from '@funfunz/json-data-connector'
import { fileURLToPath } from 'url'
const log = logger('setup/funfunz')
log('start')
Expand All @@ -14,13 +16,9 @@ const __dirname = path.dirname(__filename)

export async function generateFunfunz() {
log('building funfunz')
const module = await import(process.env.FUNFUNZ_CONNECTOR === 'sql'
? '@funfunz/sql-data-connector'
: '@funfunz/json-data-connector'
)
const connectors = {
mainDatabase: process.env.FUNFUNZ_CONNECTOR === 'sql' ? {
connector: module.Connector,
mainDatabase: {
connector: sqlDataConnector,
config: {
client: 'mysql2',
host: process.env.DB_HOST || "127.0.0.1",
Expand All @@ -29,8 +27,9 @@ export async function generateFunfunz() {
password: process.env.DB_PASS || 'password',
port: "3306",
},
} : {
connector: module.Connector,
},
jsonDatabase: {
connector: jsonDataConnector,
config: {
folderPath: path.join(__dirname, '..', '..', 'storage'),
},
Expand Down
6 changes: 3 additions & 3 deletions storage/products.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[
{
"id": 1,
"name": "Product 1",
"productName": "Product 1",
"color": "green",
"userId": 1
},
{
"id": 2,
"name": "Product 2",
"productName": "Product 2",
"color": "red",
"userId": 1
},
{
"id": 3,
"name": "Product 3",
"productName": "Product 3",
"color": "blue",
"userId": 2
}
Expand Down
2 changes: 2 additions & 0 deletions storage/productsfiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]

0 comments on commit c5b3e87

Please sign in to comment.