Skip to content

Commit

Permalink
feat: adiciona método de busca por slug na api-storefront
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabriciocaldana committed Dec 19, 2024
1 parent 439e74b commit bd548eb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/app/AppRepositoryGql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ export class AppRepositoryGql {

return app
}

static async getBySlug(slug: string, fields?: AppFields[]): Promise<App> {
const appQuery = new AppQueries(fields)
const getAppQuery: string = appQuery.getApp()
const { app }: AppResponse = await getClient().query(getAppQuery, { filter: { slug: slug } })

return app
}
}
18 changes: 18 additions & 0 deletions src/modules/app/AppRepositoryJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,22 @@ export class AppRepositoryJson {

return mock
}

static async getBySlug(slug: string, fields?: AppFields[]) {
const mock = shop_ctx.mock?.apps || {}

if (slug != mock.slug) {
throw new Error('apps_not_found')
}

const isFieldNotSelected = entry => !fields.includes(entry)

const deleteFieldIfNecessary = entry => {
isFieldNotSelected(entry) && delete mock[entry]
}

fields && Object.keys(mock).forEach(deleteFieldIfNecessary)

return mock
}
}
11 changes: 11 additions & 0 deletions src/modules/app/AppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ export class AppService {
throw new Error(error?.message)
}
}

static async getBySlug(slug: string, fields?: AppFields[]): Promise<App> {
try {
const result = await Repository().getBySlug(slug, fields)
BroadcastService.emit('Apps', result)

return result
} catch (error) {
throw new Error(error?.message)
}
}
}

0 comments on commit bd548eb

Please sign in to comment.