Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Changes for project permission type service to use schema, knex & fea…
Browse files Browse the repository at this point in the history
…thers 5 (#8367)

* Changes for project permission type service

* Made various modifications
  • Loading branch information
hurairahmateen authored Jul 25, 2023
1 parent 740fb09 commit 9b47760
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 248 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
import type { Static } from '@feathersjs/typebox'
import { querySyntax, Type } from '@feathersjs/typebox'

export const projectPermissionTypePath = 'project-permission-type'

// Main data model schema
export const projectPermissionTypeSchema = Type.Object(
{
type: Type.String()
},
{ $id: 'ProjectPermissionType', additionalProperties: false }
)
export type ProjectPermissionTypeType = Static<typeof projectPermissionTypeSchema>

// Schema for creating new entries
export const projectPermissionTypeDataSchema = Type.Pick(projectPermissionTypeSchema, ['type'], {
$id: 'ProjectPermissionTypeData'
})
export type ProjectPermissionTypeData = Static<typeof projectPermissionTypeDataSchema>

// Schema for updating existing entries
export const projectPermissionTypePatchSchema = Type.Partial(projectPermissionTypeSchema, {
$id: 'ProjectPermissionTypePatch'
})
export type ProjectPermissionTypePatch = Static<typeof projectPermissionTypePatchSchema>

// Schema for allowed query properties
export const projectPermissionTypeQueryProperties = Type.Pick(projectPermissionTypeSchema, ['type'])
export const projectPermissionTypeQuerySchema = Type.Intersect(
[
querySyntax(projectPermissionTypeQueryProperties),
// Add additional query properties here
Type.Object({}, { additionalProperties: false })
],
{ additionalProperties: false }
)
export type ProjectPermissionTypeQuery = Static<typeof projectPermissionTypeQuerySchema>
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,40 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { Application } from '../../../declarations'
import { ProjectPermissionType } from './project-permission-type.class'
import projectPermissionTypeDocs from './project-permission-type.docs'
import hooks from './project-permission-type.hooks'
import createModel from './project-permission-type.model'

declare module '@etherealengine/common/declarations' {
interface ServiceTypes {
'project-permission-type': ProjectPermissionType
import type { Knex } from 'knex'

import { projectPermissionTypePath } from '@etherealengine/engine/src/schemas/projects/project-permission-type.schema'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const oldTableName = 'project_permission_type'

const oldNamedTableExists = await knex.schema.hasTable(oldTableName)
if (oldNamedTableExists) {
await knex.schema.renameTable(oldTableName, projectPermissionTypePath)
}
}

export default (app: Application): void => {
const options = {
Model: createModel(app),
paginate: app.get('paginate'),
multi: true
const tableExists = await knex.schema.hasTable(projectPermissionTypePath)

if (tableExists === false) {
await knex.schema.createTable(projectPermissionTypePath, (table) => {
//@ts-ignore
table.string('type', 255).notNullable().unique().primary()
})
}
}

const event = new ProjectPermissionType(options, app)
event.docs = projectPermissionTypeDocs
app.use('project-permission-type', event)
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(projectPermissionTypePath)

const service = app.service('project-permission-type')
service.hooks(hooks)
if (tableExists === true) {
await knex.schema.dropTable(projectPermissionTypePath)
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,33 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

export const projectPermissionTypeSeed = {
path: 'project-permission-type',
templates: [
{
type: 'owner'
},
{
type: 'user'
import { Knex } from 'knex'

import {
projectPermissionTypePath,
ProjectPermissionTypeType
} from '@etherealengine/engine/src/schemas/projects/project-permission-type.schema'
import appConfig from '@etherealengine/server-core/src/appconfig'

export async function seed(knex: Knex): Promise<void> {
const { testEnabled } = appConfig
const { forceRefresh } = appConfig.db

const seedData: ProjectPermissionTypeType[] = await Promise.all([{ type: 'owner' }, { type: 'user' }])

if (forceRefresh || testEnabled) {
// Deletes ALL existing entries
await knex(projectPermissionTypePath).del()

// Inserts seed entries
await knex(projectPermissionTypePath).insert(seedData)
} else {
const existingData = await knex(projectPermissionTypePath).count({ count: '*' })

if (existingData.length === 0 || existingData[0].count === 0) {
for (const item of seedData) {
await knex(projectPermissionTypePath).insert(item)
}
}
]
}
}
Loading

0 comments on commit 9b47760

Please sign in to comment.