4230: added functionality for new interior generation (#156)

* added functionality for new interior generation

* update

* fixes
This commit is contained in:
Arwid Thornström
2023-09-12 11:26:17 +02:00
committed by GitHub
parent a51cbca616
commit 91d6aa1d1a
6 changed files with 65 additions and 19 deletions
+12 -9
View File
@@ -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;
}
+21
View File
@@ -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
+3 -3
View File
@@ -1,10 +1,10 @@
import { InteriorAPI } from '../datasources/interior-api';
import { InteriorsFilterInput } from '../types/interior-types';
import { InteriorsInput } from '../types/interior-types';
const Interior = {};
async function getInteriors(_, args: InteriorsFilterInput, { dataSources }) {
return (<InteriorAPI>dataSources.interiorApi).getInteriors(args.filter);
async function getInteriors(_, args: InteriorsInput, { dataSources }) {
return (<InteriorAPI>dataSources.interiorApi).getInteriors(args.input);
}
export const interiorTypeDefs = { Interior };
+16
View File
@@ -299,6 +299,22 @@ export const productMutationTypeDefs = {
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
* @description Mutate the list of interiors on a product and its groups.
+10 -4
View File
@@ -37,7 +37,7 @@ type Query {
market(name: String!): Market
locales: [Locale]
locale(value: String!): Locale
interiors(filter: InteriorsFilterInput): [Interior]
interiors(input: InteriorsInput): [Interior]
signedFileUploadURL(config: SignedUploadURLInput): SignedUploadURL
@cacheControl(maxAge: 0)
translate(input: TranslateInput!): StringResult!
@@ -111,7 +111,7 @@ type ProductsSearchResult {
references: [Product]
}
input InteriorsFilterInput {
input InteriorsInput {
productId: Int!
}
@@ -210,7 +210,9 @@ type OrderRowData {
}
type CategoryLocaleData {
path: String, name: String, locale: String
path: String
name: String
locale: String
}
type Category {
@@ -242,7 +244,7 @@ type Copyright {
}
type Facet {
attribute: String,
attribute: String
values: [String]
}
@@ -372,6 +374,9 @@ type Interior {
roomName: String
position: Int
roomType: String
"""
uri is set when there is a generated file on s3, null otherwise
"""
uri: String
roomNumber: Int
type: InteriorType
@@ -518,6 +523,7 @@ type Mutation {
"""
productGroup(productId: Int!, groupIds: [Int]): Product
productGroupInteriors(productId: Int!, groupId: Int!, uris: [String]): Product
generateInteriors(productId: Int!, roomIds: [String]!): StringResult
addOwnInteriorToPrintProduct(
printId: Int!
uploadedS3Key: String!
+3 -3
View File
@@ -18,10 +18,10 @@ export enum InteriorType {
FRAMED_PRINT,
}
export interface InteriorsFilter {
export interface InteriorsInputValues {
productId: number;
}
export interface InteriorsFilterInput {
filter?: InteriorsFilter;
export interface InteriorsInput {
input?: InteriorsInputValues;
}