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 {
|
||||
Interior,
|
||||
InteriorsFilter,
|
||||
InteriorsInputValues,
|
||||
InteriorType,
|
||||
} from '../types/interior-types';
|
||||
import { Orientation } from '../types/product-types';
|
||||
@@ -102,7 +102,9 @@ export class InteriorAPI extends BaseSQLDataSource {
|
||||
// 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([
|
||||
Scopes.INTERIORS_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 (filter) {
|
||||
// If input is set add data depending on what input contains.
|
||||
// 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(
|
||||
filter.productId,
|
||||
input.productId,
|
||||
);
|
||||
|
||||
const addZero = (number: number): string => {
|
||||
@@ -140,7 +144,7 @@ export class InteriorAPI extends BaseSQLDataSource {
|
||||
return `${number}`;
|
||||
};
|
||||
|
||||
return allInteriors.filter((i: Interior) => {
|
||||
return allInteriors.map((i: Interior) => {
|
||||
const it = i.type.toString().replace('_', '-').toLowerCase();
|
||||
const or = i.orientation.toString().toLocaleLowerCase();
|
||||
const uriMatch = `${or}/${it}/room${addZero(i.roomNumber)}.`;
|
||||
@@ -148,12 +152,11 @@ export class InteriorAPI extends BaseSQLDataSource {
|
||||
if (foundUri) {
|
||||
i.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;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,27 @@ export class InteriorsLambdaAPI extends RESTDataSource {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user