4230: added functionality for new interior generation (#156)
* added functionality for new interior generation * update * fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { ApolloServerErrorCode } from '@apollo/server/errors';
|
import { ApolloServerErrorCode } from '@apollo/server/errors';
|
||||||
import {
|
import {
|
||||||
Interior,
|
Interior,
|
||||||
InteriorsFilter,
|
InteriorsInputValues,
|
||||||
InteriorType,
|
InteriorType,
|
||||||
} from '../types/interior-types';
|
} from '../types/interior-types';
|
||||||
import { Orientation } from '../types/product-types';
|
import { Orientation } from '../types/product-types';
|
||||||
@@ -102,7 +102,9 @@ export class InteriorAPI extends BaseSQLDataSource {
|
|||||||
// Functions used in resolvers or other datasources
|
// Functions used in resolvers or other datasources
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
|
|
||||||
async getInteriors(filter: Maybe<InteriorsFilter>): Promise<Array<Interior>> {
|
async getInteriors(
|
||||||
|
input: Maybe<InteriorsInputValues>,
|
||||||
|
): Promise<Array<Interior>> {
|
||||||
ScopeAccess.validate(this.user).some([
|
ScopeAccess.validate(this.user).some([
|
||||||
Scopes.INTERIORS_READ,
|
Scopes.INTERIORS_READ,
|
||||||
Scopes.INTERIORS_PUBLIC_READ,
|
Scopes.INTERIORS_PUBLIC_READ,
|
||||||
@@ -127,10 +129,12 @@ export class InteriorAPI extends BaseSQLDataSource {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Based on filter get valid interiors and filter out any else from all interiors
|
// If input is set add data depending on what input contains.
|
||||||
if (filter) {
|
// Right now it only contains productId which will result in
|
||||||
|
// the uri value is set to the s3 file if available.
|
||||||
|
if (input) {
|
||||||
const validUris = await this.imageServerApi.getInteriorsForProduct(
|
const validUris = await this.imageServerApi.getInteriorsForProduct(
|
||||||
filter.productId,
|
input.productId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const addZero = (number: number): string => {
|
const addZero = (number: number): string => {
|
||||||
@@ -140,7 +144,7 @@ export class InteriorAPI extends BaseSQLDataSource {
|
|||||||
return `${number}`;
|
return `${number}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
return allInteriors.filter((i: Interior) => {
|
return allInteriors.map((i: Interior) => {
|
||||||
const it = i.type.toString().replace('_', '-').toLowerCase();
|
const it = i.type.toString().replace('_', '-').toLowerCase();
|
||||||
const or = i.orientation.toString().toLocaleLowerCase();
|
const or = i.orientation.toString().toLocaleLowerCase();
|
||||||
const uriMatch = `${or}/${it}/room${addZero(i.roomNumber)}.`;
|
const uriMatch = `${or}/${it}/room${addZero(i.roomNumber)}.`;
|
||||||
@@ -148,12 +152,11 @@ export class InteriorAPI extends BaseSQLDataSource {
|
|||||||
if (foundUri) {
|
if (foundUri) {
|
||||||
i.uri =
|
i.uri =
|
||||||
foundUri.uri.indexOf('/') !== 0 ? `/${foundUri.uri}` : foundUri.uri;
|
foundUri.uri.indexOf('/') !== 0 ? `/${foundUri.uri}` : foundUri.uri;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return i;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// No filter so return all
|
// No input values so return all without modification
|
||||||
return allInteriors;
|
return allInteriors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,27 @@ export class InteriorsLambdaAPI extends RESTDataSource {
|
|||||||
this.user = options.user;
|
this.user = options.user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async generateInteriors(product: Product, roomIds: String[]): Promise<any> {
|
||||||
|
ScopeAccess.validate(this.user).all([Scopes.INTERIORS_WRITE]);
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
token: process.env.INTERIORS_TOKEN,
|
||||||
|
image: `products/${product.id}.jpg`,
|
||||||
|
primary_image_area: [
|
||||||
|
product.fields.focusXpoint2,
|
||||||
|
product.fields.focusYpoint2,
|
||||||
|
],
|
||||||
|
autodetect: false,
|
||||||
|
rooms: roomIds,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isRepeatingPattern(product)) {
|
||||||
|
body['print_file_height'] = product.fields.printFileHeight;
|
||||||
|
body['print_file_dpi'] = product.fields.printFileDpi;
|
||||||
|
}
|
||||||
|
return this.post('/batch', { body: body });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param product Product with printProducts and fields
|
* @param product Product with printProducts and fields
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { InteriorAPI } from '../datasources/interior-api';
|
import { InteriorAPI } from '../datasources/interior-api';
|
||||||
import { InteriorsFilterInput } from '../types/interior-types';
|
import { InteriorsInput } from '../types/interior-types';
|
||||||
|
|
||||||
const Interior = {};
|
const Interior = {};
|
||||||
|
|
||||||
async function getInteriors(_, args: InteriorsFilterInput, { dataSources }) {
|
async function getInteriors(_, args: InteriorsInput, { dataSources }) {
|
||||||
return (<InteriorAPI>dataSources.interiorApi).getInteriors(args.filter);
|
return (<InteriorAPI>dataSources.interiorApi).getInteriors(args.input);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const interiorTypeDefs = { Interior };
|
export const interiorTypeDefs = { Interior };
|
||||||
|
|||||||
@@ -299,6 +299,22 @@ export const productMutationTypeDefs = {
|
|||||||
return product;
|
return product;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function generateInteriors
|
||||||
|
* @description Will generate one interior for a specific product
|
||||||
|
*/
|
||||||
|
async generateInteriors(_, { productId, roomIds }, { dataSources }) {
|
||||||
|
const product = await (<ProductAPI>dataSources.productApi).getProduct(
|
||||||
|
productId,
|
||||||
|
);
|
||||||
|
await (<InteriorsLambdaAPI>(
|
||||||
|
dataSources.interiorsLambdaApi
|
||||||
|
)).generateInteriors(product, roomIds);
|
||||||
|
return {
|
||||||
|
value: 'OK',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function productGroupInteriors
|
* @function productGroupInteriors
|
||||||
* @description Mutate the list of interiors on a product and its groups.
|
* @description Mutate the list of interiors on a product and its groups.
|
||||||
|
|||||||
+10
-4
@@ -37,7 +37,7 @@ type Query {
|
|||||||
market(name: String!): Market
|
market(name: String!): Market
|
||||||
locales: [Locale]
|
locales: [Locale]
|
||||||
locale(value: String!): Locale
|
locale(value: String!): Locale
|
||||||
interiors(filter: InteriorsFilterInput): [Interior]
|
interiors(input: InteriorsInput): [Interior]
|
||||||
signedFileUploadURL(config: SignedUploadURLInput): SignedUploadURL
|
signedFileUploadURL(config: SignedUploadURLInput): SignedUploadURL
|
||||||
@cacheControl(maxAge: 0)
|
@cacheControl(maxAge: 0)
|
||||||
translate(input: TranslateInput!): StringResult!
|
translate(input: TranslateInput!): StringResult!
|
||||||
@@ -111,7 +111,7 @@ type ProductsSearchResult {
|
|||||||
references: [Product]
|
references: [Product]
|
||||||
}
|
}
|
||||||
|
|
||||||
input InteriorsFilterInput {
|
input InteriorsInput {
|
||||||
productId: Int!
|
productId: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +210,9 @@ type OrderRowData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CategoryLocaleData {
|
type CategoryLocaleData {
|
||||||
path: String, name: String, locale: String
|
path: String
|
||||||
|
name: String
|
||||||
|
locale: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type Category {
|
type Category {
|
||||||
@@ -242,7 +244,7 @@ type Copyright {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Facet {
|
type Facet {
|
||||||
attribute: String,
|
attribute: String
|
||||||
values: [String]
|
values: [String]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,6 +374,9 @@ type Interior {
|
|||||||
roomName: String
|
roomName: String
|
||||||
position: Int
|
position: Int
|
||||||
roomType: String
|
roomType: String
|
||||||
|
"""
|
||||||
|
uri is set when there is a generated file on s3, null otherwise
|
||||||
|
"""
|
||||||
uri: String
|
uri: String
|
||||||
roomNumber: Int
|
roomNumber: Int
|
||||||
type: InteriorType
|
type: InteriorType
|
||||||
@@ -518,6 +523,7 @@ type Mutation {
|
|||||||
"""
|
"""
|
||||||
productGroup(productId: Int!, groupIds: [Int]): Product
|
productGroup(productId: Int!, groupIds: [Int]): Product
|
||||||
productGroupInteriors(productId: Int!, groupId: Int!, uris: [String]): Product
|
productGroupInteriors(productId: Int!, groupId: Int!, uris: [String]): Product
|
||||||
|
generateInteriors(productId: Int!, roomIds: [String]!): StringResult
|
||||||
addOwnInteriorToPrintProduct(
|
addOwnInteriorToPrintProduct(
|
||||||
printId: Int!
|
printId: Int!
|
||||||
uploadedS3Key: String!
|
uploadedS3Key: String!
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ export enum InteriorType {
|
|||||||
FRAMED_PRINT,
|
FRAMED_PRINT,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InteriorsFilter {
|
export interface InteriorsInputValues {
|
||||||
productId: number;
|
productId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InteriorsFilterInput {
|
export interface InteriorsInput {
|
||||||
filter?: InteriorsFilter;
|
input?: InteriorsInputValues;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user