3384 - add locales to market query (#147)
This commit is contained in:
@@ -73,6 +73,25 @@ export class MarketLocaleAPI extends SQLDataSource {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getLocalesForMarketId(marketId: number): Promise<Locale> {
|
||||||
|
ScopeAccess.validate(this.user).all([Scopes.LOCALES_READ]);
|
||||||
|
return (
|
||||||
|
this.knex
|
||||||
|
.select(
|
||||||
|
'market_id',
|
||||||
|
'locales.id',
|
||||||
|
'value',
|
||||||
|
'fallback_id',
|
||||||
|
'locales.name',
|
||||||
|
)
|
||||||
|
.from('market_locales')
|
||||||
|
.leftJoin('locales', 'locales.id', 'market_locales.locale_id')
|
||||||
|
.where('market_id', marketId)
|
||||||
|
// @ts-ignore
|
||||||
|
.cache(MINUTE * 5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async getLocaleByValue(value: string): Promise<Locale> {
|
async getLocaleByValue(value: string): Promise<Locale> {
|
||||||
ScopeAccess.validate(this.user).all([Scopes.LOCALES_READ]);
|
ScopeAccess.validate(this.user).all([Scopes.LOCALES_READ]);
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { MarketLocaleAPI } from '../datasources/market-locale-api';
|
import { MarketLocaleAPI } from '../datasources/market-locale-api';
|
||||||
|
|
||||||
const Market = {};
|
const Market = {
|
||||||
|
async locales({ id }, _args, { dataSources }) {
|
||||||
|
return (<MarketLocaleAPI>dataSources.marketLocaleApi).getLocalesForMarketId(
|
||||||
|
id,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
async function getMarkets(_, _args, { dataSources }) {
|
async function getMarkets(_, _args, { dataSources }) {
|
||||||
return (<MarketLocaleAPI>dataSources.marketLocaleApi).getMarkets();
|
return (<MarketLocaleAPI>dataSources.marketLocaleApi).getMarkets();
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ type Market {
|
|||||||
vat: Float!
|
vat: Float!
|
||||||
currency: String!
|
currency: String!
|
||||||
priceAdjustment: Float!
|
priceAdjustment: Float!
|
||||||
|
locales: [Locale]!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Locale {
|
type Locale {
|
||||||
|
|||||||
Reference in New Issue
Block a user