Skip to content

Commit

Permalink
updated spell get to check versions
Browse files Browse the repository at this point in the history
  • Loading branch information
benbot committed Nov 21, 2023
1 parent 7f9e84d commit c868776
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/server/core/src/services/agents/agents.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class AgentService<
return this._patch(agentId, params)
}

async remove(agentId: string, params: ServiceParams) {
async remove(agentId: string | null, params: ServiceParams) {
return this._remove(agentId, params)
}
}
Expand Down
31 changes: 29 additions & 2 deletions packages/server/core/src/services/spells/spells.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import otJson0 from 'ot-json0'
import md5 from 'md5'
import { KnexAdapter } from '@feathersjs/knex'
import { BadRequest } from '@feathersjs/errors/lib'
import { BadRequest, NotFound } from '@feathersjs/errors/lib'
import type { Application } from '../../declarations'
import type { Paginated, Params } from '@feathersjs/feathers'
import type { KnexAdapterParams, KnexAdapterOptions } from '@feathersjs/knex'
Expand All @@ -32,7 +32,34 @@ export class SpellService<
> extends KnexAdapter<SpellInterface, SpellData, ServiceParams, SpellPatch> {

async get(spellId: string, params: ServiceParams) {
return this._get(spellId, params)
const db = app.get('dbClient')
const { versionId } = params.query

const query = super.createQuery(params)

if (spellId && !versionId) {
const count = await db('agentReleases').count('*').as('count').where('id', '=', versionId)

if (count["count"] > 0) {
query
.leftJoin('agentRelease as releases', function() {
this.on('agents.id', '=', 'agentReleases.agentId')
})
}

} else if(spellId && versionId) {
query
.leftJoin('agentRelease as releases', function() {
this.on('spelld.versionId', '=', 'agentReleases.id').andOn(versionId, '=', 'agentReleases.id')
})
}

const data = await query.andWhere('spells.id', '=', spellId)
if (data.length !== 1) {
throw new NotFound(`No record found for id '${spellId}'`)
}

return data
}

async find(params: ServiceParams) {
Expand Down
21 changes: 8 additions & 13 deletions packages/shared/core/src/spellManager/SpellManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,16 @@ export default class SpellManager {
try {
const spellService = this.app.service('spells');

const spellResults = checkPaginated<SpellInterface>(await spellService.find({
query: {
$limit: 1,
$and: [
{id: spellId},
{versionId: versionId}
]
}
}))

if (spellResults.total === 0) {
this.logger.error({spellId, versionId}, `Error loading spell %s with version %s: %s`, spellId, versionId)
const query: { versionId?: string } = {}
if (versionId) {
query.versionId = versionId
}

const spell = spellResults.data[0]
const spell = await spellService.get(spellId, { query })

if (!spell) {
this.logger.error({spellId, versionId}, `Error loading spell %s with version %s: %s`, spellId, versionId)
}

if (
this.hasSpellRunner(spellId) &&
Expand Down

0 comments on commit c868776

Please sign in to comment.