id
stringlengths
12
53
messages
listlengths
3
3
code_mycheckout-checkout-service_b7172a1a
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/dtos/paymentVtex.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses/api-error';\nimport {\n IsInt,\n IsNotEmpty,\n IsString,\n ValidationArguments,\n} from 'class-validator';\nimport { Type } from 'class-transformer';\n\nexport class PaymentVtexDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n paymentSystem: string;\n\n @IsInt({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_integer', args),\n })\n @Type(() => Number)\n referenceValue: number;\n\n @IsInt({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_integer', args),\n })\n @Type(() => Number)\n value: number;\n}\n\n```" } ]
code_mycheckout-checkout-service_39c0af95
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/dtos/orderVtex.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses/api-error';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class OrderVtexDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n orderGroup: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n addressId: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n currencyCode: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_1aed973d
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/orders.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { OrdersVTEXService } from './orders.service';\n\nconst HttpServiceProvider = {\n provide: HttpService,\n useFactory: () => ({}),\n};\n\ndescribe('OrdersService', () => {\n let service: OrdersVTEXService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [OrdersVTEXService, HttpServiceProvider],\n }).compile();\n\n service = module.get<OrdersVTEXService>(OrdersVTEXService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_fd2f5bdb
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/orders.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { CheckoutVTEXService } from './checkout/checkout.service';\nimport { CartVTEXService } from './cart/cart.service';\nimport { PaymentVTEXService } from './payment/payment.service';\n\n@Injectable()\nexport class OrdersVTEXService {\n constructor(\n public checkout: CheckoutVTEXService,\n public cart: CartVTEXService,\n public payment: PaymentVTEXService,\n ) {}\n}\n\n```" } ]
code_mycheckout-checkout-service_70bc25f3
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/payment/payment.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService, Injectable } from '@nestjs/common';\nimport { map } from 'rxjs/operators';\nimport { CreateAccountDto } from 'src/app/accounts/dtos/createAccount.dto';\nimport { OrderVtexDto } from '../../dtos/orderVtex.dto';\nimport { TransactionVtexDto } from '../../dtos/transactionVtex.dto';\nimport { PaymentData } from '../../../../typings/OrderContext';\nimport { GatewayException } from 'src/shared/exceptions/gateway-exception';\n\n@Injectable()\nexport class PaymentVTEXService {\n constructor(private httpService: HttpService) {}\n\n async sendPaymentData(\n accountData: CreateAccountDto,\n transaction: TransactionVtexDto,\n order: OrderVtexDto,\n headers: any,\n paymentData?: PaymentData,\n ) {\n const payments = [];\n transaction.payments.forEach((payment) => {\n payments.push({\n paymentSystem: payment.paymentSystem,\n installments: 1,\n installmentsInterestRate: 0,\n installmentsValue: 0,\n Value: payment.value,\n referenceValue: payment.referenceValue,\n bin: paymentData?.bin,\n fields: {\n holderName: paymentData?.holderName,\n cardNumber: paymentData?.cardNumber,\n validationCode: paymentData?.cvv,\n accountId: (paymentData.additionalData as any)?.accountId,\n dueDate: paymentData?.expirationDate,\n addressId: order.addressId,\n bin: paymentData?.bin,\n },\n transaction: {\n id: transaction.transactionId,\n merchantName: transaction.merchantName,\n },\n currencyCode: order.currencyCode,\n });\n });\n\n try {\n return this.httpService\n .post(\n `https://${accountData.account}.vtexpayments.com.br/api/pub/transactions/${transaction.transactionId}/payments`,\n payments,\n {\n headers: {\n ...headers,\n },\n },\n )\n .pipe(map((response: any) => response.status))\n .toPromise();\n } catch (err) {\n throw new GatewayException(\n 'VTEX: Error send payment data',\n err.response?.data,\n order,\n );\n }\n }\n\n async requestPaymentProcess(\n accountData: CreateAccountDto,\n checkoutCookie: string,\n order: OrderVtexDto,\n headers: any,\n ) {\n try {\n return this.httpService\n .post(\n `http://${accountData.account}.vtexcommercestable.com.br/api/checkout/pub/gatewayCallback/${order.orderGroup}`,\n null,\n {\n headers: {\n Vtex_CHKO_Auth: checkoutCookie,\n ...headers,\n },\n },\n )\n .pipe(\n map((response: any) => {\n return {\n status: response.status === 200 || response.status === 204,\n message: 'ok',\n };\n }),\n )\n .toPromise();\n } catch (err) {\n throw new GatewayException(\n 'VTEX: Error send payment data',\n err.response?.data,\n order,\n );\n }\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_0e02c045
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/payment/payment.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { PaymentVTEXService } from './payment.service';\n\nconst HttpServiceProvider = {\n provide: HttpService,\n useFactory: () => ({}),\n};\n\ndescribe('CartVTEXService', () => {\n let service: PaymentVTEXService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [PaymentVTEXService, HttpServiceProvider],\n }).compile();\n\n service = module.get<PaymentVTEXService>(PaymentVTEXService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_018e51f0
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/checkout/checkout.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CheckoutVTEXService } from './checkout.service';\n\nconst HttpServiceProvider = {\n provide: HttpService,\n useFactory: () => ({}),\n};\n\ndescribe('CheckoutVTEXService', () => {\n let service: CheckoutVTEXService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [CheckoutVTEXService, HttpServiceProvider],\n }).compile();\n\n service = module.get<CheckoutVTEXService>(CheckoutVTEXService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_90bc665a
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/checkout/checkout.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable, HttpService } from '@nestjs/common';\nimport { map } from 'rxjs/operators';\nimport { AccountDoc } from '../../../accounts/schemas/account.schema';\nimport { CustomDataDto } from '../../../orders/dtos/customData.dto';\nimport { MarketingDataDto } from '../../../orders/dtos/marketingData.dto';\nimport { AddressDoc } from '../../../users/addresses/schemas/address.schema';\nimport { ProfileDoc } from '../../../users/profiles/schemas/profile.schema';\nimport { Item, PaymentData } from '../../../../typings/OrderContext';\nimport { ProfileSystemVTEXService } from '../../profile-system/profile-system.service';\nimport { findBestMatch } from 'string-similarity';\nimport * as crypto from 'crypto';\n\n@Injectable()\nexport class CheckoutVTEXService {\n constructor(\n private httpService: HttpService,\n private profileSystemVtexService: ProfileSystemVTEXService,\n ) {}\n\n async createOrder(\n accountData: AccountDoc,\n simulationData: CheckoutOrderForm,\n user: ProfileDoc,\n addresses: AddressDoc[],\n total: number,\n items: Item[],\n gifts?: Item[],\n customData?: CustomDataDto,\n marketingData?: MarketingDataDto,\n paymentData?: PaymentData,\n headers?: any,\n ) {\n const userVtex = await this.profileSystemVtexService.getUserInfo(\n accountData,\n user.email,\n headers,\n );\n\n let addressesVtex: any;\n if (userVtex) {\n addressesVtex = await this.profileSystemVtexService.getUserAddress(\n accountData,\n user,\n { userId: userVtex.id },\n headers,\n );\n }\n let dataAddress = {};\n if (addresses[0]) {\n dataAddress = this.dataAddress(\n addresses[0],\n this.matchVtexAddress(addressesVtex, addresses[0]) || addresses[0].id,\n 'residential',\n user,\n );\n }\n const dataAddresses = [];\n const logisticsInfo = simulationData.logisticsInfo.map((itemLogistic) => {\n const sla = itemLogistic.slas.find(\n (slaItem) => slaItem.id === itemLogistic.selectedSla,\n );\n let slaAddress: any = {};\n let residential;\n if (sla.pickupStoreInfo.isPickupStore) {\n residential = false;\n slaAddress = {\n ...sla.pickupStoreInfo.address,\n addressId: crypto\n .createHash('md5')\n .update(JSON.stringify(sla.pickupStoreInfo.address))\n .digest('hex'),\n };\n } else {\n residential = true;\n slaAddress = dataAddress;\n }\n const exits = dataAddresses.find(\n (address) => address.addressId === slaAddress.addressId,\n );\n if (!exits) {\n dataAddresses.push(slaAddress);\n if (!residential)\n addresses.push({\n id: slaAddress.addressId,\n street: slaAddress.street,\n number: slaAddress.number || '0',\n city: slaAddress.city,\n state: slaAddress.state,\n country: slaAddress.country,\n geoCoordinates: {\n longitude: slaAddress.geoCoordinates[0].toString(),\n latitude: slaAddress.geoCoordinates[1].toString(),\n },\n postalCode: slaAddress.postalCode,\n reference: slaAddress.reference || '',\n receiverName: slaAddress.receiverName || '',\n neighborhood: slaAddress.neighborhood || '',\n } as any);\n }\n\n return {\n itemIndex: itemLogistic.itemIndex,\n selectedSla: sla.id,\n selectedDeliveryChannel: itemLogistic.selectedDeliveryChannel,\n price: sla.price,\n deliveryWindow: sla.deliveryWindow,\n addressId: slaAddress.addressId,\n };\n });\n\n const data: any = {\n items: [...items, ...(gifts || [])],\n clientProfileData: {\n email: user?.email,\n firstName: user.name,\n lastName: user.lastname,\n document: user.document,\n documentType: user.documentType,\n phone: user.phoneNumber,\n corporateName: null,\n tradeName: null,\n corporateDocument: null,\n stateInscription: null,\n corporatePhone: null,\n isCorporate: false,\n },\n shippingData: {\n id: 'shippingData',\n address: dataAddress,\n selectedAddresses: dataAddresses,\n logisticsInfo: logisticsInfo,\n },\n paymentData: {\n id: 'paymentData',\n payments: [\n {\n bin: paymentData.bin,\n paymentSystem: Number.parseInt(accountData.paymentMethodId),\n referenceValue: total,\n value: total,\n installments: (paymentData.additionalData as any)?.installments\n ? (paymentData.additionalData as any).installments\n : 1,\n },\n ],\n },\n marketingData: {\n coupon: marketingData?.coupon,\n utmiCampaign: 'kuikpay',\n marketingTags: ['kuikpay'],\n },\n };\n\n if (customData) {\n const customApps = [];\n customData.customApps.forEach((apps) => {\n const fields = {};\n apps.fields.forEach((data) => {\n fields[data.key] = data.value;\n });\n customApps.push({\n ...apps,\n fields: fields,\n });\n });\n data.customData = {\n customApps: customApps,\n };\n }\n\n return this.httpService\n .put(\n `https://${accountData.account}.vtexcommercestable.com.br/api/checkout/pub/orders`,\n data,\n {\n headers: {\n ...headers,\n },\n },\n )\n .pipe(\n map((response: any) => ({\n data: response.data,\n headers: response.headers,\n })),\n )\n .toPromise();\n }\n\n matchVtexAddress(addressesVtex, address) {\n const addresses = addressesVtex?.map(\n (address: AddressDoc) => address.street,\n );\n let matchAddress;\n if (addresses && addresses.length) {\n try {\n const { bestMatch } = findBestMatch(address.street, addresses);\n\n if (bestMatch.rating === 1) {\n matchAddress = addressesVtex.find(\n (address: any) => address.street == bestMatch.target,\n );\n }\n } catch (error) {\n console.log(`error`, error);\n }\n return matchAddress && matchAddress.addressName;\n }\n }\n\n dataAddress(address, addressId, addressType, user) {\n const dataAddress = {\n addressId: addressId,\n addressType: addressType,\n receiverName: address.receiverName\n ? address.receiverName\n : `${user.name} ${user.lastname}`,\n postalCode: address.postalCode,\n city: address.city,\n state: address.state,\n country: address.country,\n street: address.street,\n number: address.number,\n neighborhood: address.neighborhood,\n complement: address.complement || address.reference,\n reference: address.reference,\n geoCoordinates: [\n address.geoCoordinates.longitude,\n address.geoCoordinates.latitude,\n ],\n };\n return dataAddress;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_f8b0b6de
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/cart/cart.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CartVTEXService } from './cart.service';\n\nconst HttpServiceProvider = {\n provide: HttpService,\n useFactory: () => ({}),\n};\n\ndescribe('CartVTEXService', () => {\n let service: CartVTEXService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [CartVTEXService, HttpServiceProvider],\n }).compile();\n\n service = module.get<CartVTEXService>(CartVTEXService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_eb8e50f7
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/vtex/orders/cart/cart.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService, Injectable } from '@nestjs/common';\nimport { map } from 'rxjs/operators';\nimport { MarketingDataDto } from 'src/app/orders/dtos/marketingData.dto';\nimport { PaymentDataDto } from 'src/app/orders/dtos/paymentData.dto';\nimport { GatewayException } from 'src/shared/exceptions/gateway-exception';\nimport { ItemDto } from '../../../orders/dtos/item.dto';\nimport { GeoCoordinateDto } from '../../../users/addresses/dtos/geoCoordinates.dto';\n\n@Injectable()\nexport class CartVTEXService {\n constructor(private httpService: HttpService) {}\n\n async cartSimulation(\n account: string,\n items: ItemDto[],\n address: {\n postalCode: string;\n geoCoordinates: GeoCoordinateDto;\n country: string;\n },\n logisticsInfo: LogisticInfoInput[],\n marketingData?: MarketingDataDto,\n paymentData?: PaymentDataDto,\n paymentMethodId?: string,\n ) {\n const data: any = {\n items,\n postalCode: address.postalCode,\n country: address.country,\n geoCoordinates: [\n address.geoCoordinates?.longitude,\n address.geoCoordinates?.latitude,\n ],\n shippingData: {\n logisticsInfo: logisticsInfo.map((li) => ({\n selectedDeliveryWindow: li.deliveryWindow,\n selectedSlaId: li.selectedSla,\n ...li,\n })),\n },\n paymentData: {\n payments: [{ bin: paymentData?.bin, paymentSystem: paymentMethodId }],\n },\n };\n\n if (marketingData?.coupon) {\n data.marketingData = marketingData;\n }\n try {\n return this.httpService\n .post(\n `https://${account}.vtexcommercestable.com.br/api/checkout/pub/orderforms/simulation`,\n data,\n )\n .pipe(map((res: any) => res.data))\n .toPromise();\n } catch (err) {\n throw new GatewayException('VTEX: Error in cart simulation', err, data);\n }\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_0c20815d
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/sms/sms.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { CommunicationService } from '../communication/communication.service';\n\n@Injectable()\nexport class SMSService {\n constructor(private readonly communication: CommunicationService) {}\n notify(data): Promise<any> {\n return this.communication.twilio.sms(data);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_8d3550c7
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/sms/sms.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CommunicationService } from '../communication/communication.service';\nimport { SMSService } from './sms.service';\n\nconst CommunicationServiceProvider = {\n provide: CommunicationService,\n useFactory: () => ({}),\n};\n\ndescribe('SmsService', () => {\n let service: SMSService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [SMSService, CommunicationServiceProvider],\n }).compile();\n\n service = module.get<SMSService>(SMSService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_45638a9e
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/mailer/mailer.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable, HttpService } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\n\n@Injectable()\nexport class MailerService {\n private readonly url =\n 'http://mailservice.vtex.com.br/api/mail-service/pvt/sendmail?an=briancarmona';\n\n constructor(\n private readonly httpService: HttpService,\n private readonly configService: ConfigService,\n ) {\n const url = this.configService.get('MAIL_SERVICE_HOST');\n this.url = url && url != '' ? url : this.url;\n }\n\n notify(data): Promise<any> {\n const headers = {\n 'X-VTEX-API-AppKey': this.configService.get('MAILER_VTEX_APP_KEY'),\n 'X-VTEX-API-AppToken': this.configService.get('MAILER_VTEX_APP_TOKEN'),\n };\n\n return this.httpService\n .post(this.url, data, { headers: headers })\n .toPromise();\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_71d40858
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/mailer/mailer.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { MailerService } from './mailer.service';\n\nconst ConfigServiceProvider = {\n provide: ConfigService,\n useFactory: () => ({\n get() {\n return {};\n },\n }),\n};\n\nconst HttpServiceProvider = {\n provide: HttpService,\n useFactory: () => ({}),\n};\n\ndescribe('MailerService', () => {\n let service: MailerService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [MailerService, ConfigServiceProvider, HttpServiceProvider],\n }).compile();\n\n service = module.get<MailerService>(MailerService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_2beadc0b
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/aws/aws.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { TransactionQueue } from '../../../typings/vtex/order';\nimport { Injectable } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport * as SQS from 'aws-sdk/clients/sqs';\n\n@Injectable()\nexport class AwsService {\n private sqs: SQS;\n private queueNamePT: string;\n constructor(private readonly configService: ConfigService) {\n this.sqs = new SQS({\n credentials: {\n accessKeyId: this.configService.get('AWS_ACCESS_KEY_ID'),\n secretAccessKey: this.configService.get('AWS_SECRET_ACCESS_KEY'),\n },\n region: 'us-west-2',\n });\n this.queueNamePT = this.configService.get('AWS_QUEUE_ORDER');\n }\n\n sendTransactionProcessorQueue(\n message: TransactionQueue | Partial<TransactionQueue>,\n ): Promise<SQS.SendMessageResult> {\n return new Promise((resolve, reject) => {\n const params: SQS.Types.SendMessageRequest = {\n MessageBody: JSON.stringify(message),\n MessageDeduplicationId: message.orderId,\n MessageGroupId: 'checkoutless-transaction',\n QueueUrl: `https://sqs.us-east-1.amazonaws.com/666555811597/${this.queueNamePT}.fifo`,\n };\n this.sqs.sendMessage(params, (err, data) => {\n if (err) {\n reject(err);\n } else {\n resolve(data);\n }\n });\n });\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_2bbeae45
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/aws/aws.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ConfigService } from '@nestjs/config';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { AwsService } from './aws.service';\n\nconst ConfigServiceProvider = {\n provide: ConfigService,\n useFactory: () => ({\n get() {\n return {};\n },\n }),\n};\n\ndescribe('AwsService', () => {\n let service: AwsService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [AwsService, ConfigServiceProvider],\n }).compile();\n\n service = module.get<AwsService>(AwsService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_1be9ca36
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/communication/communication.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InfobipService } from './infobip/infobip.service';\nimport { TwilioService } from './twilio/twilio.service';\n\n@Injectable()\nexport class CommunicationService {\n public readonly twilio;\n public readonly infobip;\n constructor(twilioService: TwilioService, infobipService: InfobipService) {\n this.twilio = twilioService;\n this.infobip = infobipService;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_d0404418
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/communication/communication.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CommunicationService } from './communication.service';\nimport { InfobipService } from './infobip/infobip.service';\nimport { TwilioService } from './twilio/twilio.service';\n\nconst InfobipServiceProvider = {\n provide: InfobipService,\n useFactory: () => ({}),\n};\n\nconst TwillioServiceProvide = {\n provide: TwilioService,\n useFactory: () => ({}),\n};\n\ndescribe('CommunicationService', () => {\n let service: CommunicationService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [\n CommunicationService,\n TwillioServiceProvide,\n InfobipServiceProvider,\n ],\n }).compile();\n\n service = module.get<CommunicationService>(CommunicationService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_3860ad48
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/communication/communication.module.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpModule, Module } from '@nestjs/common';\nimport { TwilioService } from './twilio/twilio.service';\nimport { InfobipService } from './infobip/infobip.service';\nimport { CommunicationService } from './communication.service';\n\n@Module({\n imports: [HttpModule],\n providers: [TwilioService, InfobipService, CommunicationService],\n exports: [CommunicationService],\n})\nexport class CommunicationModule {}\n\n```" } ]
code_mycheckout-checkout-service_d22be5af
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/communication/infobip/infobip.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { InfobipService } from './infobip.service';\n\nconst ConfigServiceProvider = {\n provide: ConfigService,\n useFactory: () => ({\n get() {\n return {};\n },\n }),\n};\n\nconst HttpServiceProvider = {\n provide: HttpService,\n useFactory: () => ({}),\n};\n\ndescribe('InfobipService', () => {\n let service: InfobipService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [InfobipService, ConfigServiceProvider, HttpServiceProvider],\n }).compile();\n\n service = module.get<InfobipService>(InfobipService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_d1da5234
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/communication/infobip/infobip.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService, Injectable } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\n\n@Injectable()\nexport class InfobipService {\n private readonly headers;\n private readonly url;\n constructor(\n private readonly configService: ConfigService,\n private readonly httpClient: HttpService,\n ) {\n this.url = `https://jxvyj.api.infobip.com/sms/2/text/advanced`;\n this.headers = {\n Authorization: `App ${this.configService.get('INFOBIP_APP_KEY')}`,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n };\n }\n\n sms(data) {\n return this.httpClient\n .post(\n this.url,\n {\n messages: [\n {\n from: 'InfoSMS',\n destinations: [\n {\n to: data.to,\n },\n ],\n\n text: data.body,\n },\n ],\n },\n { headers: this.headers },\n )\n .toPromise()\n .catch((e) => console.log('SMS', e));\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_dd6673d0
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/communication/twilio/twilio.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ConfigService } from '@nestjs/config';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { TwilioService } from './twilio.service';\n\njest.mock('twilio', () => {\n return jest.fn(() => null);\n});\n\nconst ConfigServiceProvider = {\n provide: ConfigService,\n useFactory: () => ({\n get() {\n return {};\n },\n }),\n};\n\ndescribe('TwilioService', () => {\n let service: TwilioService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [TwilioService, ConfigServiceProvider],\n }).compile();\n\n service = module.get<TwilioService>(TwilioService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_ce119e28
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/common/communication/twilio/twilio.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport * as twilio from 'twilio';\n\n@Injectable()\nexport class TwilioService {\n private readonly phone;\n private readonly client;\n constructor(private readonly configService: ConfigService) {\n const accountSid = this.configService.get('TWILIO_ACCOUNT_SID');\n const authToken = this.configService.get('TWILIO_AUTH_TOKEN');\n this.phone = this.configService.get('TWILIO_PHONE_NUMBER');\n this.client = twilio(accountSid, authToken);\n }\n\n sms(data) {\n return this.client.messages\n .create({\n body: data.body,\n from: this.phone,\n to: data.to,\n })\n .catch((e) => console.log('SMS', e));\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_f5d8970d
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/accounts-links/accounts-links.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { AccountsLinksController } from './accounts-links.controller';\nimport { AccountsLinksService } from './accounts-links.service';\n\ndescribe('AccountsLinksController', () => {\n let controller: AccountsLinksController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: AccountsLinksService,\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n controllers: [AccountsLinksController],\n providers: [ApiServiceProvider],\n }).compile();\n\n controller = module.get<AccountsLinksController>(AccountsLinksController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_ca1f5b61
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/accounts-links/accounts-links.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Body,\n Controller,\n Delete,\n Get,\n Post,\n Put,\n Param,\n} from '@nestjs/common';\nimport { AccountsLinksService } from './accounts-links.service';\nimport { CreateAccountLinkDto } from './dtos/createAccountLink.dto';\nimport { UpdateAccountLinkDto } from './dtos/updateAccountLink.dto';\n\n@Controller('accounts/links')\nexport class AccountsLinksController {\n constructor(private accountsLinksService: AccountsLinksService) {}\n\n @Post()\n linkRequest(@Body() createAccountLinkDto: CreateAccountLinkDto) {\n return this.accountsLinksService.linkRequest(createAccountLinkDto);\n }\n\n @Get(':account')\n getLinkRequest(@Param('account') account: string) {\n return this.accountsLinksService.getLinkRequest(account);\n }\n\n @Put('')\n linkUpdate(@Body() accountLinkDto: UpdateAccountLinkDto) {\n return this.accountsLinksService.linkUpdate(\n accountLinkDto.id,\n accountLinkDto.status,\n );\n }\n\n @Delete(':id')\n deleteLink(@Param('id') id: string) {\n return this.accountsLinksService.deleteLink(id);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_e7100a20
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/accounts-links/accounts-links.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { AccountLink, AccountLinkModel } from './schemas/account-link.schema';\nimport { ApiResponse } from '../../../shared/responses';\nimport { CreateAccountLinkDto } from './dtos/createAccountLink.dto';\nimport { HttpStatus, Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\n\n@Injectable()\nexport class AccountsLinksService {\n constructor(\n @InjectModel(AccountLink.name)\n private accountsLinksModel: AccountLinkModel,\n ) {}\n\n async linkRequest(accountLinkDto: CreateAccountLinkDto) {\n if (accountLinkDto.accountRequester === accountLinkDto.accountApprover) {\n throw ApiResponse.error('errors.link_exist', {}, HttpStatus.BAD_REQUEST);\n }\n\n const query = async (query) => {\n return await this.accountsLinksModel\n .query(query)\n .where('status')\n .not()\n .eq('removed')\n .and()\n .where('status')\n .not()\n .eq('rejected')\n .exec();\n };\n\n const q1 = await query({\n accountRequester: accountLinkDto.accountApprover,\n accountApprover: accountLinkDto.accountRequester,\n });\n const q2 = await query({\n accountRequester: accountLinkDto.accountRequester,\n accountApprover: accountLinkDto.accountApprover,\n });\n\n const existLink = [...q1, ...q2];\n\n if (!existLink || (existLink && existLink.length > 0)) {\n throw ApiResponse.error('errors.link_exist', {}, HttpStatus.BAD_REQUEST);\n }\n\n const accountLink = this.accountsLinksModel.build({\n accountRequester: accountLinkDto.accountRequester,\n accountApprover: accountLinkDto.accountApprover,\n date: new Date(),\n });\n\n return accountLink.save();\n }\n\n async getLinkRequest(account: string) {\n const query = async (query) => {\n return await this.accountsLinksModel\n .query(query)\n .where('status')\n .not()\n .eq('removed')\n .exec();\n };\n const req = await query({ accountRequester: account });\n const appr = await query({ accountApprover: account });\n\n return [...req, ...appr];\n }\n\n async linkUpdate(id: string, status: string) {\n const accountLink = await this.accountsLinksModel.get(id);\n\n if (!accountLink) {\n throw ApiResponse.error('errors.not_found', {}, HttpStatus.BAD_REQUEST);\n }\n\n accountLink.set({ status });\n return accountLink.save();\n }\n\n async deleteLink(id: string) {\n const accountLink = await this.accountsLinksModel.get(id);\n\n if (!accountLink) {\n throw ApiResponse.error('errors.not_found', {}, HttpStatus.BAD_REQUEST);\n }\n\n accountLink.set({ status: 'removed' });\n accountLink.save();\n return {\n removed: 1,\n };\n }\n\n async getLinkedAccounts(account: string) {\n const query = (query) => {\n return this.accountsLinksModel\n .query({ ...query, status: 'approved' })\n .exec();\n };\n const q1 = query({\n accountRequester: account,\n });\n const q2 = query({\n accountApprover: account,\n });\n const links = await Promise.all([q1, q2]);\n return [...links[0], ...links[1]];\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_e0da1244
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/accounts-links/accounts-links.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { getModelToken } from 'nestjs-dynamoose';\nimport { AccountsLinksService } from './accounts-links.service';\nimport { AccountLink } from './schemas/account-link.schema';\n\ndescribe('AccountsLinksService', () => {\n let service: AccountsLinksService;\n\n beforeEach(async () => {\n const AccountLinkModel = {\n provide: getModelToken(AccountLink.name),\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n providers: [AccountsLinksService, AccountLinkModel],\n }).compile();\n\n service = module.get<AccountsLinksService>(AccountsLinksService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_3eb367f0
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/schemas/account.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface AccountAttrs {\n additionalData?: {\n key: string;\n value: string;\n }[];\n account: string;\n buttonMessage?: string;\n buttonText: string;\n createdAt: number;\n cvcRequired: boolean;\n habeasDataInformation?: {\n url: string;\n version: number;\n };\n hasGoogleAnalytics?: boolean;\n isTracking?: boolean;\n paymentMethodId: string;\n paymentRedirect?: boolean;\n styles: string;\n trackingKey?: string;\n visualization: {\n key: string;\n secondaryKey: string;\n type: string;\n }[];\n}\n\nexport interface AccountDoc extends Document {\n additionalData?: {\n key: string;\n value: string;\n }[];\n account: string;\n buttonMessage?: string;\n buttonText: string;\n createdAt: number;\n cvcRequired: boolean;\n habeasDataInformation?: {\n url: string;\n version: number;\n };\n hasGoogleAnalytics?: boolean;\n isConfigured: boolean;\n isTracking?: boolean;\n paymentMethodId: string;\n paymentRedirect?: boolean;\n styles: string;\n trackingKey?: string;\n visualization: {\n key: string;\n secondaryKey: string;\n type: string;\n }[];\n}\n\nexport type AccountModel = Model<AccountDoc, AccountAttrs>;\n\nconst AccountSchema = Schema.build({\n account: {\n type: String,\n required: true,\n index: { global: true, name: 'accountIndex' },\n },\n paymentMethodId: String,\n buttonMessage: String,\n styles: String,\n buttonText: String,\n cvcRequired: { type: Boolean, default: false },\n visualization: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n type: { type: String },\n key: String,\n secondaryKey: String,\n },\n },\n ],\n },\n paymentRedirect: { type: Boolean, default: false },\n hasGoogleAnalytics: { type: Boolean, default: false },\n isTracking: { type: Boolean, default: false },\n trackingKey: { type: String, default: '' },\n createdAt: { type: Number },\n additionalData: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n key: String,\n value: String,\n },\n },\n ],\n },\n});\n\nexport const Account: ModelDefinition = {\n name: 'accounts',\n schema: AccountSchema,\n methods: {\n transform: (ret: AccountDoc) => {\n ret.isConfigured = true;\n },\n },\n};\n\n```" } ]
code_mycheckout-checkout-service_becc3b85
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/dtos/createAccount.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses/api-error';\nimport {\n IsBoolean,\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { VisualizationDto } from './visualizationDto.dto';\nimport { Type } from 'class-transformer';\n\nexport class CreateAccountDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n account: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n paymentMethodId?: string;\n\n @IsOptional()\n @IsBoolean({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n cvcRequired?: boolean;\n\n @IsOptional()\n @ValidateNested()\n @Type(() => VisualizationDto)\n visualization: VisualizationDto[];\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n buttonMessage?: string;\n\n additionalData?: any;\n}\n\n```" } ]
code_mycheckout-checkout-service_7e1bf4ac
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/dtos/visualizationDto.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsIn,\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../shared/responses';\n\nexport class VisualizationDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsIn(['category', 'product', 'collection'])\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n type: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n key: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n secondaryKey: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_f3a6cd82
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/styles.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { Account, AccountModel } from '../schemas/account.schema';\nimport { NotFoundException } from '../../../shared/exceptions/not-found-exception';\nimport { ValidationException } from '../../../shared/exceptions/validation-exception';\nimport { BASE_STYLES, validateData } from './utils/validate';\nimport { StylesDto } from './dtos/Styles.dto';\nimport { UploadCSS } from './uploadCssToS3';\n\n@Injectable()\nexport class StylesService {\n constructor(\n @InjectModel(Account.name)\n private accountModel: AccountModel,\n private uploadCSS: UploadCSS,\n ) {}\n\n async save(customDto: StylesDto, accountName: string) {\n const account = await this.accountModel\n .findOne({ account: accountName })\n .exec();\n\n if (!account) {\n throw new NotFoundException();\n }\n\n try {\n await validateData(customDto.styles, BASE_STYLES);\n } catch (e) {\n throw new ValidationException(e.message, e.errors, customDto.styles);\n }\n\n const buttonText = customDto.buttonText;\n const stylesParse = JSON.parse(customDto.styles);\n const restore = customDto.restore;\n await this.uploadCSS.uploadFile(accountName, stylesParse, restore);\n\n account.set({\n styles: customDto.styles,\n buttonText,\n });\n\n await account.save();\n\n return account;\n }\n\n async findByAccount(accountName: string) {\n const account = await this.accountModel\n .findOne({ account: accountName })\n .exec();\n\n if (!account) {\n throw new NotFoundException();\n }\n\n return account;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_3ad89480
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/styles.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { StylesService } from './styles.service';\n\ndescribe('StylesService', () => {\n let service: StylesService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [StylesService],\n }).compile();\n\n service = module.get<StylesService>(StylesService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_3cf8896e
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/uploadCssToS3.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport * as AWS from 'aws-sdk';\nimport * as fs from 'fs';\nimport { customCss } from './utils/customCss';\nimport { defaultCss } from './utils/defaultCss';\n\n@Injectable()\nexport class UploadCSS {\n private S3: any;\n private cloudfront: any;\n private enviroment: string;\n constructor(private readonly configService: ConfigService) {\n const config = {\n accessKeyId: this.configService.get('AWS_ACCESS_KEY_ID'),\n secretAccessKey: this.configService.get('AWS_SECRET_ACCESS_KEY'),\n };\n\n this.S3 = new AWS.S3(config);\n this.cloudfront = new AWS.CloudFront(config);\n this.enviroment = process.env.NODE_ENV\n ? process.env.NODE_ENV\n : 'development';\n }\n\n async uploadFile(account: string, styleCustom: any, restore = true) {\n const file = `${account}-vtex-mc.css`;\n const data = restore ? defaultCss() : customCss(styleCustom);\n\n fs.writeFile(file, data, (err) => {\n if (err) throw err;\n const params = {\n Bucket: this.configService.get('AWS_STYLES_BUCKET'),\n Key: `${file}`,\n Body: fs.createReadStream(file),\n ContentType: 'text/css; charset=utf-8',\n Accept:\n 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',\n };\n this.S3.upload(params, function (s3Err, dat) {\n if (s3Err) throw s3Err;\n return dat.Location;\n });\n });\n\n if (this.enviroment !== 'development') {\n await this.invalitadeCache(file);\n }\n }\n\n async invalitadeCache(key: string) {\n const params = {\n DistributionId: this.configService.get('AWS_STYLES_CF_DISTRIBUTION_ID'),\n InvalidationBatch: {\n CallerReference: new Date().getTime().toString(),\n Paths: {\n Quantity: 1,\n Items: [`/${key}`],\n },\n },\n };\n\n this.cloudfront.createInvalidation(params, function (err, data) {\n if (err) throw err;\n return data;\n });\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_0ccf4eb6
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/styles.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { StylesController } from './styles.controller';\n\ndescribe('StylesController', () => {\n let controller: StylesController;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n controllers: [StylesController],\n }).compile();\n\n controller = module.get<StylesController>(StylesController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_18659c88
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/styles.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Body, Controller, Get, Post, Query } from '@nestjs/common';\nimport { StylesService } from './styles.service';\nimport { StylesDto } from './dtos/Styles.dto';\n\n@Controller('accounts/styles')\nexport class StylesController {\n constructor(private stylesService: StylesService) {}\n\n @Post()\n save(@Body() StylesDto: StylesDto, @Query('an') accountName: string) {\n return this.stylesService.save(StylesDto, accountName);\n }\n\n @Get()\n findByAccount(@Query('an') accountName: string) {\n return this.stylesService.findByAccount(accountName);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_d416c861
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/habeasData.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { HabeasDataController } from './habeasData.controller';\nimport { HabeasDataService } from './habeasData.service';\n\ndescribe('HabeasDataController', () => {\n let controller: HabeasDataController;\n\n beforeEach(async () => {\n const HabeasDataProvider = {\n provide: HabeasDataService,\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n controllers: [HabeasDataController],\n providers: [HabeasDataProvider],\n }).compile();\n\n controller = module.get<HabeasDataController>(HabeasDataController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_74975102
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/habeasData.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { getModelToken } from 'nestjs-dynamoose';\nimport { HabeasDataService } from './habeasData.service';\nimport { HabeasData } from './schemas/habeasdata.schema';\n\ndescribe('HabeasDataService', () => {\n let service: HabeasDataService;\n\n beforeEach(async () => {\n const HabeasDataModel = {\n provide: getModelToken(HabeasData.name),\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n providers: [HabeasDataService, HabeasDataModel],\n }).compile();\n\n service = module.get<HabeasDataService>(HabeasDataService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_931cbabe
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/habeasData.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Body, Controller, Get, Post } from '@nestjs/common';\nimport { CreateHabeasDataDto } from './dtos/createHabeasData.dto';\nimport { HabeasDataService } from './habeasData.service';\n\n@Controller('habeasdata')\nexport class HabeasDataController {\n constructor(private habeasdataService: HabeasDataService) {}\n\n @Post()\n habeasdataCreate(@Body() habeasdataDto: CreateHabeasDataDto) {\n return this.habeasdataService.create(habeasdataDto);\n }\n\n @Get()\n getByActiveState() {\n return this.habeasdataService.getByActiveState();\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_fb954126
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/habeasData.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus, Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { ApiResponse } from 'src/shared/responses';\nimport { CreateHabeasDataDto } from './dtos/createHabeasData.dto';\nimport { HabeasData, HabeasDataModel } from './schemas/habeasdata.schema';\n\n@Injectable()\nexport class HabeasDataService {\n constructor(\n @InjectModel(HabeasData.name)\n private habeasdataModel: HabeasDataModel,\n ) {}\n\n async create(habeasdataDto: CreateHabeasDataDto) {\n const { version, id } = await this.getByActiveState();\n\n const newVersion = version + 1;\n\n const { statu } = await this.updateState(id);\n\n if (statu === 'inactive') {\n const habeasDataDto = {\n statu: 'active',\n url: habeasdataDto.url,\n version: newVersion,\n };\n\n const habeasdata = this.habeasdataModel.build(habeasDataDto);\n\n await habeasdata.save();\n\n return habeasdata;\n } else {\n throw ApiResponse.error('error.not_update', {}, HttpStatus.BAD_REQUEST);\n }\n }\n\n async updateState(id: string) {\n const habeasData = await this.habeasdataModel.get(id);\n\n habeasData.set({ statu: 'inactive' });\n await habeasData.save();\n\n return habeasData;\n }\n\n async getByActiveState() {\n const habeasDataActive = await this.habeasdataModel\n .findOne({ statu: 'active' })\n .exec();\n\n return habeasDataActive;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_f761f8c1
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/payment-methods/payment-methods.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Controller, Body, Post, Get, Query } from '@nestjs/common';\nimport { PaymentMethodsService } from './payment-methods.service';\nimport { createPaymentMethodDto } from './dtos/createPaymentMethod.dto';\n\n@Controller('accounts/payment-methods')\nexport class PaymentMethodsController {\n constructor(private paymentMethodsService: PaymentMethodsService) {}\n\n @Get()\n findByAccount(@Query('an') accountName: string) {\n return this.paymentMethodsService.findByAccount(accountName);\n }\n\n @Post()\n createPaymentMethod(\n @Body() paymentMethod: createPaymentMethodDto,\n @Query('an') an: string,\n ) {\n return this.paymentMethodsService.createPaymentMethod(paymentMethod, an);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_6cbcd77b
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/payment-methods/payment-methods.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Provider } from '@nestjs/common';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { getModelToken } from 'nestjs-dynamoose';\nimport { AccountsService } from '../accounts.service';\nimport { PaymentMethodsService } from './payment-methods.service';\nimport { PaymentMethod } from './schemas/payment-method.schema';\n\ndescribe('PaymentMethodsService', () => {\n let service: PaymentMethodsService;\n\n beforeEach(async () => {\n const model: Provider = {\n provide: getModelToken(PaymentMethod.name),\n useValue: {},\n };\n\n const accountsService: Provider = {\n provide: AccountsService,\n useValue: {},\n };\n const module: TestingModule = await Test.createTestingModule({\n providers: [PaymentMethodsService, accountsService, model],\n }).compile();\n\n service = module.get<PaymentMethodsService>(PaymentMethodsService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_ffd18248
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/payment-methods/payment-methods.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Provider } from '@nestjs/common';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { PaymentMethodsController } from './payment-methods.controller';\nimport { PaymentMethodsService } from './payment-methods.service';\n\ndescribe('PaymentMethodsController', () => {\n let controller: PaymentMethodsController;\n\n beforeEach(async () => {\n const service: Provider = {\n provide: PaymentMethodsService,\n useValue: {},\n };\n\n const module: TestingModule = await Test.createTestingModule({\n controllers: [PaymentMethodsController],\n providers: [service],\n }).compile();\n\n controller = module.get<PaymentMethodsController>(PaymentMethodsController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_cdd9fa3f
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/payment-methods/payment-methods.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { AccountsService } from '../../accounts/accounts.service';\nimport { ApiResponse } from '../../../shared/responses';\nimport { Injectable, HttpStatus, Inject, forwardRef } from '@nestjs/common';\nimport {\n PaymentMethodModel,\n PaymentMethod,\n} from './schemas/payment-method.schema';\nimport { createPaymentMethodDto } from './dtos/createPaymentMethod.dto';\nimport { InjectModel } from 'nestjs-dynamoose';\n\n@Injectable()\nexport class PaymentMethodsService {\n constructor(\n @InjectModel(PaymentMethod.name)\n private paymentMethodModel: PaymentMethodModel,\n @Inject(forwardRef(() => AccountsService))\n private accountService: AccountsService,\n ) {}\n\n async findByAccount(accountName: string) {\n return await this.paymentMethodModel\n .query({ accountName: accountName })\n .exec();\n }\n\n async createPaymentMethod(payment: createPaymentMethodDto, an: string) {\n const account = await this.accountService.get({ account: an });\n if (!account) {\n throw ApiResponse.error('errors.not_found', {}, HttpStatus.BAD_REQUEST);\n } else {\n if (payment.id) {\n const paymentsMethods = await this.paymentMethodModel.get(payment.id);\n if (paymentsMethods) {\n paymentsMethods.set(payment);\n return paymentsMethods.save();\n } else {\n return this.paymentMethodModel.build(payment).save();\n }\n } else {\n return this.paymentMethodModel.build(payment).save();\n }\n }\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_1e9a57ec
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/accounts-links/schemas/account-link.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface AccountLinkAttrs {\n accountRequester: string;\n accountApprover: string;\n date: Date;\n}\n\nexport interface AccountLinkDoc extends Document {\n accountRequester: string;\n accountApprover: string;\n date: Date;\n status: string;\n}\n\nexport type AccountLinkModel = Model<AccountLinkDoc, AccountLinkAttrs>;\n\nconst AccountLinkSchema = Schema.build({\n accountRequester: {\n type: String,\n required: true,\n index: { global: true, name: 'accountRequesterIndex' },\n },\n accountApprover: {\n type: String,\n required: true,\n index: { global: true, name: 'accountApproverIndex' },\n },\n date: { type: Date, required: true },\n status: {\n type: String,\n required: true,\n default: 'pending',\n index: { global: true, name: 'statusIndex' },\n },\n});\n\nexport const AccountLink: ModelDefinition = {\n name: 'accountLinks',\n schema: AccountLinkSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_9468462f
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/accounts-links/dtos/updateAccountLink.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses/api-error';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class UpdateAccountLinkDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n status: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_c448459b
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/accounts-links/dtos/createAccountLink.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses/api-error';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class CreateAccountLinkDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n accountRequester: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n accountApprover: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_dd60eda3
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/utils/defaultCss.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport const defaultCss = () => `\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer {\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer\n ._kuikpay-myCheckoutButton__myCheckoutButtonContent {\n width: 100%;\n background-color: #ffffff;\n border: 1px solid #011d1a;\n color: #011d1a;\n border-radius: 8px;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer\n ._kuikpay-myCheckoutButton__myCheckoutButtonContent:hover {\n background-color: #ff572d;\n border-color: #ff572d;\n color: #ffffff;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer\n ._kuikpay-myCheckoutButton__myCheckoutButtonText {\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer:hover\n ._kuikpay-myCheckoutButton__myCheckoutButtonText {\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless p,\n._kuikpay-myCheckout-styles-module__Checkoutless a,\n._kuikpay-myCheckout-styles-module__Checkoutless div,\n._kuikpay-myCheckout-styles-module__Checkoutless input,\n._kuikpay-myCheckout-styles-module__Checkoutless select {\n font-family: 'Calibri', sans-serif;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-modal__modalContainer {\n background-color: #ffffff;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless \n ._kuikpay-button__buttonContent \n ._kuikpay-button__buttonContainer {\n background-color: #ffffff;\n border: 1.5px solid #ff572d;\n color: #ff572d;\n border-radius: 12px;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless \n ._kuikpay-button__buttonContent \n ._kuikpay-button__buttonContainer:hover {\n background-color: #ff572d;\n color: #ffffff\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless \n ._kuikpay-button__buttonContent \n ._kuikpay-button__buttonContainer[disabled] {\n border: 1px solid #919191;\n background-color: #ffffff;\n color: #919191;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless \n ._kuikpay-input__inputContent \n ._kuikpay-input__input {\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckout-styles-module__iconAlternative {\n fill: #011d1a;\n}`;\n\n```" } ]
code_mycheckout-checkout-service_0b90b222
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/utils/validate.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport * as yup from 'yup';\n\nyup.addMethod(yup.array, 'mustContain', function (args) {\n return this.test('mustContain', 'Miss some required values', function (list) {\n return args && list && !args.some((l: unknown) => !list.includes(l));\n });\n});\n\nconst BASE_BUTTON = yup.object().shape({\n font: yup.string().required(),\n borderRadius: yup.string().required(),\n width: yup.string().required(),\n normal: yup\n .object()\n .shape({\n textColor: yup.string().required(),\n backgroundColor: yup.string().required(),\n outlineColor: yup.string().required(),\n })\n .required(),\n hover: yup\n .object()\n .shape({\n textColor: yup.string().required(),\n backgroundColor: yup.string().required(),\n outlineColor: yup.string().required(),\n })\n .required(),\n});\n\nconst BASE_MODAL = yup.object().shape({\n font: yup.string().required(),\n backgroundColor: yup.string().required(),\n button: yup\n .object()\n .shape({\n borderRadius: yup.string().required(),\n normal: yup\n .object()\n .shape({\n textColor: yup.string().required(),\n backgroundColor: yup.string().required(),\n outlineColor: yup.string().required(),\n })\n .required(),\n hover: yup\n .object()\n .shape({\n textColor: yup.string().required(),\n backgroundColor: yup.string().required(),\n outlineColor: yup.string().required(),\n })\n .required(),\n })\n .required(),\n icons: yup\n .object()\n .shape({\n color: yup.string().required(),\n })\n .required(),\n});\n\nexport const BASE_STYLES = yup.object().shape({\n button: BASE_BUTTON,\n modal: BASE_MODAL,\n});\n\nexport const validateData = async (data: string, validation: yup.AnySchema) => {\n const dataJson = JSON.parse(data);\n\n await validation.validate(dataJson);\n};\n\n```" } ]
code_mycheckout-checkout-service_2305978a
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/utils/customCss.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport const customCss = (data: any) =>\n `/* Document\n ========================================================================== */\n \n/*\n Styles generated by mycheckout\n*/\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer\n ._kuikpay-myCheckoutButton__myCheckoutButtonText {\n color: ${data.button.normal.textColor};\n font-family: ${data.button.font};\n }\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer:hover\n ._kuikpay-myCheckoutButton__myCheckoutButtonText {\n color: ${data.button.hover.textColor};\n }\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer\n ._kuikpay-myCheckoutButton__myCheckoutButtonContent {\n background-color: ${data.button.normal.backgroundColor};\n border: 1px solid ${data.button.normal.outlineColor};\n border-radius: ${data.button.borderRadius}px;\n width: ${data.button.width}%;\n }\n \n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckoutButton__myCheckoutButtonContainer\n ._kuikpay-myCheckoutButton__myCheckoutButtonContent:hover {\n background-color: ${data.button.hover.backgroundColor};\n border: 1px solid ${data.button.hover.outlineColor};\n border-radius: ${data.button.borderRadius}px;\n }\n \n\n._kuikpay-myCheckout-styles-module__Checkoutless p,\n._kuikpay-myCheckout-styles-module__Checkoutless a,\n._kuikpay-myCheckout-styles-module__Checkoutless div,\n._kuikpay-myCheckout-styles-module__Checkoutless input,\n._kuikpay-myCheckout-styles-module__Checkoutless select {\n font-family: ${data.modal.font};\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-modal__modalContainer {\n background-color: ${data.modal.backgroundColor};\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-input__inputContent \n ._kuikpay-input__input {\n background-color: ${data.modal.backgroundColor};\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-button__buttonContent \n ._kuikpay-button__buttonContainer {\n background-color: ${data.modal.button.normal.backgroundColor};\n border: 1px solid ${data.modal.button.normal.outlineColor};\n color: ${data.modal.button.normal.textColor};\n border-radius: ${data.modal.button.borderRadius}px;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless \n ._kuikpay-button__buttonContent \n ._kuikpay-button__buttonContainer:hover {\n background-color: ${data.modal.button.hover.backgroundColor};\n border: 1px solid ${data.modal.button.hover.outlineColor};\n color: ${data.modal.button.hover.textColor};\n border-radius: ${data.modal.button.borderRadius}px;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-button__buttonContent \n ._kuikpay-button__buttonContainer[disabled] {\n border: 1px solid #919191;\n background-color: #ffffff;\n color: #919191;\n}\n\n._kuikpay-myCheckout-styles-module__Checkoutless\n ._kuikpay-myCheckout-styles-module__iconAlternative {\n fill: ${data.modal.icons.color};\n}`;\n\n```" } ]
code_mycheckout-checkout-service_f36d5488
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/utils/stylesBase.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport const StylesButtonSchema = {\n font: 'Helvetica',\n borderRadius: 25,\n normal: {\n textColor: '#ED6400',\n backgroundColor: '#000000',\n outlineColor: '#898989',\n },\n hover: {\n textColor: '#ED6400',\n backgroundColor: '#000000',\n outlineColor: '#898989',\n },\n width: 100,\n};\n\nexport const StylesModalSchema = {\n font: 'Helvetica',\n backgroundColor: '#ED6400',\n button: {\n borderRadius: 25,\n normal: {\n textColor: '#ED6400',\n backgroundColor: '#000000',\n outlineColor: '#898989',\n },\n hover: {\n textColor: '#ED6400',\n backgroundColor: '#000000',\n outlineColor: '#898989',\n },\n },\n icons: {\n color: '#ED6400',\n },\n};\n\nexport const TextButton = `Compra Ya`;\n\nexport const StylesSchema = {\n button: StylesButtonSchema,\n modal: StylesModalSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_5d1ff9d6
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/styles/dtos/Styles.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses';\nimport {\n IsNotEmpty,\n IsString,\n IsBoolean,\n ValidationArguments,\n} from 'class-validator';\n\nexport class StylesDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n styles: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n buttonText: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsBoolean({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n restore: boolean;\n}\n\n```" } ]
code_mycheckout-checkout-service_3c863ebd
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/schemas/acceptanceHabeasData.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Document,\n Model,\n ModelDefinition,\n Schema,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface AcceptanceHabeasDataAttrs {\n action: string;\n date: number;\n document: string;\n documentType: string;\n email: string;\n ip: string;\n url: string;\n version: number;\n}\n\nexport interface AcceptanceHabeasDataDoc extends Document {\n action: string;\n date: number;\n document: string;\n documentType: string;\n email: string;\n ip: string;\n url: string;\n version: number;\n}\n\nexport type AcceptanceHabeasDataModel = Model<\n AcceptanceHabeasDataDoc,\n AcceptanceHabeasDataAttrs\n>;\n\nconst AcceptanceHabeasDataSchema = Schema.build({\n action: {\n type: String,\n required: true,\n },\n date: {\n type: Number,\n required: true,\n },\n document: {\n type: String,\n required: true,\n },\n documentType: {\n type: String,\n required: true,\n },\n email: {\n type: String,\n required: true,\n index: { global: true, name: 'acceptanceHabeasDataEmailIndex' },\n },\n ip: {\n type: String,\n required: true,\n },\n url: {\n type: String,\n required: true,\n },\n version: {\n type: Number,\n required: true,\n },\n});\n\nexport const AcceptanceHabeasData: ModelDefinition = {\n name: 'acceptanceHabeasData',\n schema: AcceptanceHabeasDataSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_367ce0e6
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/schemas/habeasdata.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Document,\n Model,\n ModelDefinition,\n Schema,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface HabeasDataAttrs {\n statu: string;\n url: string;\n version: number;\n}\n\nexport interface HabeasDataDoc extends Document {\n statu: string;\n url: string;\n version: number;\n}\n\nexport type HabeasDataModel = Model<HabeasDataDoc, HabeasDataAttrs>;\n\nconst HabeasDataSchema = Schema.build({\n statu: {\n type: String,\n default: 'active',\n index: { global: true, name: 'habeasDataStatuIndex' },\n },\n url: { type: String, required: true },\n version: {\n type: Number,\n required: true,\n },\n});\n\nexport const HabeasData: ModelDefinition = {\n name: 'habeasData',\n schema: HabeasDataSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_e6022ad6
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/dtos/createHabeasData.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from 'src/shared/responses';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class CreateHabeasDataDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n url: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_427d0041
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/dtos/createAcceptanceHabeasData.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsEmail,\n IsNotEmpty,\n IsNumber,\n IsString,\n MaxLength,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from 'src/shared/responses';\n\nexport class CreateAcceptanceHabeasDataDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @MaxLength(30, {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_greater', args),\n })\n document: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n documentType: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsEmail(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_email', args),\n },\n )\n email: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n ip: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n url: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsNumber()\n version: number;\n}\n\n```" } ]
code_mycheckout-checkout-service_1e6aceb7
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/acceptanceHabeasData/acceptanceHabeasData.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { getModelToken } from 'nestjs-dynamoose';\nimport { Test, TestingModule } from '@nestjs/testing';\n\nimport { AcceptanceHabeasData } from '../schemas/acceptanceHabeasData.schema';\nimport { AcceptanceHabeasDataService } from './acceptanceHabeasData.service';\n\ndescribe('HabeasDataService', () => {\n let service: AcceptanceHabeasDataService;\n\n beforeEach(async () => {\n const acceptanceHabeasDataModel = {\n provide: getModelToken(AcceptanceHabeasData.name),\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n providers: [AcceptanceHabeasDataService, acceptanceHabeasDataModel],\n }).compile();\n\n service = module.get<AcceptanceHabeasDataService>(AcceptanceHabeasDataService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_1aa1eecb
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/acceptanceHabeasData/acceptanceHabeasData.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\n\nimport { CreateAcceptanceHabeasDataDto } from '../dtos/createAcceptanceHabeasData.dto';\nimport {\n AcceptanceHabeasData,\n AcceptanceHabeasDataModel,\n} from '../schemas/acceptanceHabeasData.schema';\n\n@Injectable()\nexport class AcceptanceHabeasDataService {\n constructor(\n @InjectModel(AcceptanceHabeasData.name)\n private acceptanceHabeasDataModel: AcceptanceHabeasDataModel,\n ) {}\n\n async create(acceptanceHabeasDataDto: CreateAcceptanceHabeasDataDto) {\n const acceptanceHabeasData = {\n action: `El Cliente acepta autorización de tratamiento de datos en la aplicación mycheckout. ${acceptanceHabeasDataDto.url}`,\n date: Date.now(),\n document: acceptanceHabeasDataDto.document,\n documentType: acceptanceHabeasDataDto.documentType,\n email: acceptanceHabeasDataDto.email,\n ip: acceptanceHabeasDataDto.ip,\n url: acceptanceHabeasDataDto.url,\n version: acceptanceHabeasDataDto.version,\n };\n\n const acceptanceHabeasDataSave =\n this.acceptanceHabeasDataModel.build(acceptanceHabeasData);\n\n await acceptanceHabeasDataSave.save();\n\n return acceptanceHabeasDataSave;\n }\n\n async getByEmail(email: string, version: number) {\n const acceptanceHabeasData = this.acceptanceHabeasDataModel\n .findOne({ email, version })\n .exec();\n\n return acceptanceHabeasData;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_db262d33
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/acceptanceHabeasData/acceptanceHabeasData.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\n\nimport { AcceptanceHabeasDataController } from './acceptanceHabeasData.controller';\nimport { AcceptanceHabeasDataService } from './acceptanceHabeasData.service';\n\ndescribe('HabeasDataController', () => {\n let controller: AcceptanceHabeasDataController;\n\n beforeEach(async () => {\n const acceptanceHabeasDataProvider = {\n provide: AcceptanceHabeasDataService,\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n controllers: [AcceptanceHabeasDataController],\n providers: [acceptanceHabeasDataProvider],\n }).compile();\n\n controller = module.get<AcceptanceHabeasDataController>(\n AcceptanceHabeasDataController,\n );\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_77643530
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/habeasData/acceptanceHabeasData/acceptanceHabeasData.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Body,\n Controller,\n Get,\n Param,\n ParseIntPipe,\n Post,\n} from '@nestjs/common';\nimport { CreateAcceptanceHabeasDataDto } from '../dtos/createAcceptanceHabeasData.dto';\nimport { AcceptanceHabeasDataService } from './acceptanceHabeasData.service';\n\n@Controller('habeasdata/acceptance')\nexport class AcceptanceHabeasDataController {\n constructor(\n private acceptanceHabeasDataService: AcceptanceHabeasDataService,\n ) {}\n\n @Post()\n create(@Body() acceptanceHabeasDataDto: CreateAcceptanceHabeasDataDto) {\n return this.acceptanceHabeasDataService.create(acceptanceHabeasDataDto);\n }\n\n @Get(':email/:version')\n getByEmail(\n @Param('email') email: string,\n @Param('version', ParseIntPipe) version: number,\n ) {\n return this.acceptanceHabeasDataService.getByEmail(email, version);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_b7dfd70d
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/payment-methods/schemas/payment-method.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface PaymentMethodAttr {\n accountName: string;\n paymentMethodName: string;\n isActive: boolean;\n type: string;\n}\n\nexport interface PaymentMethodDoc extends Document {\n accountName: string;\n paymentMethodName: string;\n isActive: boolean;\n type: string;\n}\n\nexport type PaymentMethodModel = Model<PaymentMethodDoc, PaymentMethodAttr>;\n\nconst PaymentMethodSchema = Schema.build({\n accountName: {\n type: String,\n required: true,\n index: { global: true, name: 'accountNameIndex' },\n },\n paymentMethodName: { type: String, required: true },\n type: String,\n isActive: { type: Boolean, required: true, default: false },\n});\n\nexport const PaymentMethod: ModelDefinition = {\n name: 'paymentMethods',\n schema: PaymentMethodSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_c693e14b
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/payment-methods/dtos/createPaymentMethod.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses/api-error';\nimport {\n IsBoolean,\n IsNotEmpty,\n IsString,\n IsOptional,\n IsEnum,\n ValidationArguments,\n} from 'class-validator';\n\nenum Types {\n store,\n own,\n}\nexport class createPaymentMethodDto {\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id?: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n accountName: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n paymentMethodName: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsBoolean({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n isActive: boolean;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsEnum(Types, {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_enum', args),\n })\n type: keyof typeof Types;\n}\n\n```" } ]
code_mycheckout-checkout-service_69287022
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/accounts/payment-methods/dtos/updatePaymentMethod.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses/api-error';\nimport {\n IsBoolean,\n IsNotEmpty,\n IsString,\n IsOptional,\n IsEnum,\n ValidationArguments,\n} from 'class-validator';\n\nenum Types {\n store,\n own,\n}\nexport class updatePaymentMethodDto {\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n paymentMethodId?: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n accountName: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n paymentMethodName: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsBoolean({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n isActive: boolean;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsEnum(Types, {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_enum', args),\n })\n type: keyof typeof Types;\n}\n\n```" } ]
code_mycheckout-checkout-service_d8f92288
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/auth/auth.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Body, Controller, Param, Post, Query, Headers } from '@nestjs/common';\nimport { GeneralResponse } from '../../../shared/responses/general-response';\nimport { AuthService } from './auth.service';\n\n@Controller('/users/auth')\nexport class AuthController {\n constructor(private authService: AuthService) {}\n\n @Post(`/:email`)\n async login(\n @Body('origin') origin: string,\n @Param('email') email: string,\n @Query('an') an: string,\n @Headers() headers,\n ): Promise<GeneralResponse> {\n return this.authService.login(\n email,\n an,\n origin,\n headers.vtexidclientautcookie,\n );\n }\n\n @Post(`/verify/:email`)\n async validate(\n @Body('code') code: number,\n @Param('email') email: string,\n @Query('an') account: string,\n @Headers() headers,\n ): Promise<GeneralResponse> {\n return this.authService.validate(\n email,\n code,\n account,\n headers.vtexidclientautcookie,\n );\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_95d27f0e
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/auth/auth.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus, Injectable } from '@nestjs/common';\nimport { JwtService } from '@nestjs/jwt';\nimport { classToPlain } from 'class-transformer';\nimport { I18nService } from 'nestjs-i18n';\nimport { MailerService } from '../../common/mailer/mailer.service';\nimport { SMSService } from '../../common/sms/sms.service';\nimport { ApiResponse } from '../../../shared/responses';\nimport { ProfilesService } from '../profiles/profiles.service';\nimport { UserDoc } from '../schemas/user.schema';\nimport { UsersService } from '../users.service';\nimport { ODTCodeData } from './dtos/odt.code.data';\nimport { PasswordCodes } from './dtos/password_codes.enum';\nimport { Auth, AuthModel } from './schemas/auth.schema';\nimport { InjectModel } from 'nestjs-dynamoose';\n\n@Injectable()\nexport class AuthService {\n constructor(\n @InjectModel(Auth.name)\n private readonly authModel: AuthModel,\n private readonly usersService: UsersService,\n private profilesService: ProfilesService,\n private readonly jwtService: JwtService,\n private readonly mailerService: MailerService,\n private readonly smsService: SMSService,\n private readonly i18nService: I18nService,\n ) {}\n\n async login(\n email: string,\n accountName: string,\n origin: string,\n authToken: string,\n ): Promise<any> {\n try {\n const user = await this.usersService.getUserByEmail(email);\n\n if (!user) {\n throw ApiResponse.error('errors.user_doesnt_exist');\n }\n\n const headers = {\n VtexIdclientAutCookie: authToken,\n };\n\n return this.codeAssign(user, accountName, origin, headers);\n } catch {\n throw ApiResponse.error('errors.bad_gateway');\n }\n }\n\n async validate(\n email: string,\n code: number,\n account: string,\n authToken: string,\n ): Promise<any> {\n try {\n const auth = await this.authModel.findOne({ email }).exec();\n\n if (!auth) {\n throw ApiResponse.error(\n 'errors.non_existent_code',\n null,\n HttpStatus.FORBIDDEN,\n );\n }\n\n const passwordCode = await auth.validatePassword(String(code));\n\n if (passwordCode !== PasswordCodes.valid) {\n auth.set({\n attempts: auth.attempts,\n validateLockedUntil: auth.validateLockedUntil,\n });\n\n await auth.save();\n\n throw ApiResponse.error(\n `errors.${passwordCode}`,\n null,\n HttpStatus.FORBIDDEN,\n );\n } else {\n await auth.delete();\n const headers = {\n VtexIdclientAutCookie: authToken,\n };\n const profile = await this.profilesService.getProfileInfo(\n email,\n account,\n headers,\n );\n const accessToken = this.jwtService.sign(\n classToPlain({ email, id: profile.id, account }),\n );\n\n return ApiResponse.send('authenticated', {\n ...profile.toJSON(),\n accessToken,\n });\n }\n } catch (e) {\n if (e?.response?.message) throw e;\n throw ApiResponse.error('errors.bad_gateway');\n }\n }\n\n private async codeAssign(\n user: UserDoc,\n accountName: string,\n origin: string,\n headers: any,\n ) {\n const auth = await this.authModel.findOne({ email: user.email }).exec();\n\n const newAuth = this.authModel.build({ email: user.email });\n const password = this.authModel.generatePassword();\n if (!auth) {\n newAuth.set({\n password,\n });\n await newAuth.save();\n return this.notify(user, password, accountName, origin, headers);\n } else {\n if (auth.isLocked()) {\n throw ApiResponse.error('errors.locked_action');\n } else {\n await auth.delete();\n newAuth.set({\n password,\n });\n\n await newAuth.save();\n\n return this.notify(user, password, accountName, origin, headers);\n }\n }\n }\n\n private async notify(\n user: UserDoc,\n password: string,\n accountName: string,\n origin: string,\n headers: any,\n ) {\n try {\n const profile = await this.profilesService.getProfileInfo(\n user.email,\n accountName,\n headers,\n );\n\n const data = ODTCodeData;\n data.JsonData.to[0].email = user.email;\n data.JsonData.to[0].name = profile.name;\n data.JsonData.aditionalData.accessKey = password;\n\n this.mailerService.notify(data);\n\n // Disabling sms service notification\n // const body = await this.i18nService.translate('responses.sms_body', {\n // args: { name: profile.name, code: password, origin },\n // });\n // this.smsService.notify({\n // to: profile.phoneCode + profile.phoneNumber,\n // body,\n // });\n\n return ApiResponse.send('responses.user_login_sent');\n } catch {\n throw ApiResponse.error('errors.internal_error');\n }\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_95d0c0e0
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/auth/auth.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { getModelToken } from '@nestjs/mongoose';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { I18nService } from 'nestjs-i18n';\nimport { SMSService } from '../../common/sms/sms.service';\nimport { MailerService } from '../../common/mailer/mailer.service';\nimport { ProfilesService } from '../profiles/profiles.service';\nimport { UsersService } from '../users.service';\nimport { AuthService } from './auth.service';\nimport { Auth } from './schemas/auth.schema';\nimport { JwtService } from '@nestjs/jwt';\n\nconst UserServiceProvider = {\n provide: UsersService,\n useFactory: () => ({}),\n};\n\nconst AuthModel = {\n provide: getModelToken(Auth.name),\n useFactory: () => ({}),\n};\n\nconst ProfilesServiceProvider = {\n provide: ProfilesService,\n useFactory: () => ({}),\n};\n\nconst JwtServiceProvider = {\n provide: JwtService,\n useFactory: () => ({}),\n};\n\nconst MailerServiceProvider = {\n provide: MailerService,\n useFactory: () => ({}),\n};\n\nconst SmsServiceProvider = {\n provide: SMSService,\n useFactory: () => ({}),\n};\n\nconst I18nServiceProvider = {\n provide: I18nService,\n useFactory: () => ({}),\n};\n\ndescribe('AuthService', () => {\n let service: AuthService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [\n AuthService,\n AuthModel,\n UserServiceProvider,\n ProfilesServiceProvider,\n JwtServiceProvider,\n MailerServiceProvider,\n SmsServiceProvider,\n I18nServiceProvider,\n ],\n }).compile();\n\n service = module.get<AuthService>(AuthService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_910baf32
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/auth/auth.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { AuthController } from './auth.controller';\nimport { AuthService } from './auth.service';\n\ndescribe('AuthController', () => {\n let controller: AuthController;\n let service: AuthService;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: AuthService,\n useFactory: () => ({\n save: jest.fn(() => ({})),\n findByAccount: jest.fn(() => ({})),\n }),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n controllers: [AuthController],\n providers: [ApiServiceProvider],\n }).compile();\n\n controller = module.get<AuthController>(AuthController);\n service = module.get<AuthService>(AuthService);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_c6f79a5c
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/cards/cards.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { AccountsService } from 'src/app/accounts/accounts.service';\nimport { encrypt } from 'src/shared/utils/encription';\nimport { ApiResponse } from '../../../shared/responses';\nimport { ProfilesService } from '../profiles/profiles.service';\nimport { ProfileDoc } from '../profiles/schemas/profile.schema';\nimport { UserDoc } from '../schemas/user.schema';\nimport { UsersService } from '../users.service';\nimport { CardDto } from './dtos/card.dto';\nimport { Card, CardModel } from './schemas/cards.schema';\n\n@Injectable()\nexport class CardsService {\n constructor(\n @InjectModel(Card.name) private cardModel: CardModel,\n private usersService: UsersService,\n private accountsService: AccountsService,\n private profilesService: ProfilesService,\n ) {}\n\n async findByEmail(email: string, an: string) {\n const user = await this.usersService.getUserByEmail(email);\n const account = await this.accountsService.get({ account: an });\n if (!user || !account) return [];\n const profiles = await this.profilesService.getByUserAccount(user);\n if (!profiles || profiles.count == 0) return [];\n return this.cardModel.query({ profile: profiles[0].id }).exec();\n }\n\n //TODO: Create CardDTO instead PaymentDataDto\n async create(paymentDto: CardDto, profile: ProfileDoc) {\n const card = this.cardModel.build({\n token: encrypt(paymentDto.token),\n franchise: paymentDto.franchise,\n number: paymentDto.number,\n gateway: paymentDto.gateway,\n cardContent: paymentDto.cardContent,\n bin: paymentDto.bin,\n paymentSystem: paymentDto.paymentSystem,\n holderDocument: paymentDto.holderDocument,\n holderName: paymentDto.holderName,\n expirationDate: paymentDto.expirationDate,\n cardNumber: paymentDto.cardNumber,\n cvv: paymentDto.cvv,\n aliasCVV: 'null',\n aliasCC: paymentDto.aliasCC,\n internalCardContent: paymentDto.internalCardContent,\n profile,\n user: profile.user as UserDoc,\n });\n\n return card.save();\n }\n\n async update(paymentDto: Partial<CardDto>, id: string) {\n const card = await this.cardModel.get(id);\n if (paymentDto.token) paymentDto.token = encrypt(paymentDto.token);\n card?.set(paymentDto);\n return card?.save();\n }\n\n get(id: string) {\n return this.cardModel.get(id);\n }\n\n async delete(id: string) {\n const card = await this.cardModel.get(id);\n await card?.delete();\n return ApiResponse.send('responses.resource_deleted', card);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_373e96a7
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/cards/cards.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { AuthGuard } from '../../../shared/guards/auth.guard';\nimport {\n Body,\n Controller,\n Delete,\n Get,\n Param,\n Post,\n Query,\n UseGuards,\n} from '@nestjs/common';\nimport { CardsService } from './cards.service';\nimport { CardDto } from './dtos/card.dto';\nimport { ProfileDoc } from '../profiles/schemas/profile.schema';\n\n@Controller('users/cards')\nexport class CardsController {\n constructor(private cardsService: CardsService) {}\n\n @Get(':email')\n getAllByEmail(@Param('email') email: string, @Query('an') an: string) {\n return this.cardsService.findByEmail(email, an);\n }\n\n @Delete(':id')\n @UseGuards(AuthGuard)\n delete(@Param('id') id: string) {\n return this.cardsService.delete(id);\n }\n\n @Post()\n create(@Body() card: CardDto) {\n return this.cardsService.create(card, { id: null } as ProfileDoc);\n }\n\n @Post('update')\n update(@Body() card: CardDto) {\n return this.cardsService.update(card, '');\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_381e0ed2
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/cards/cards.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { JwtService } from '@nestjs/jwt';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { ProfilesService } from '../profiles/profiles.service';\nimport { CardsController } from './cards.controller';\nimport { CardsService } from './cards.service';\n\nconst JwtServiceProvider = {\n provide: JwtService,\n useFactory: () => ({}),\n};\n\nconst ProfileServiceProvider = {\n provide: ProfilesService,\n useFactory: () => ({}),\n};\n\ndescribe('CardsController', () => {\n let controller: CardsController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: CardsService,\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n controllers: [CardsController],\n providers: [\n ApiServiceProvider,\n JwtServiceProvider,\n ProfileServiceProvider,\n ],\n }).compile();\n\n controller = module.get<CardsController>(CardsController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_53a3d152
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/cards/cards.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { getModelToken } from '@nestjs/mongoose';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CardsService } from './cards.service';\nimport { Card } from './schemas/cards.schema';\n\ndescribe('CardsService', () => {\n let service: CardsService;\n\n beforeEach(async () => {\n const CardModel = {\n provide: getModelToken(Card.name),\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n providers: [CardsService, CardModel],\n }).compile();\n\n service = module.get<CardsService>(CardsService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_b2c722e7
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/schemas/user.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface UserAttrs {\n email: string;\n creationDate: string;\n createdAccount: string;\n createdAt: number;\n}\n\nexport interface UserDoc extends Document {\n email: string;\n creationDate: string;\n createdAccount: string;\n createdAt: number;\n}\n\nexport type UserModel = Model<UserDoc, UserAttrs>;\n\nconst UserSchema = Schema.build({\n email: {\n type: String,\n required: true,\n index: { global: true, name: 'emailIndex' },\n },\n creationDate: { type: String },\n createdAccount: {\n type: String,\n required: true,\n index: { global: true, name: 'accountIndex' },\n },\n createdAt: { type: Number },\n});\n\nexport const User: ModelDefinition = {\n name: 'users',\n schema: UserSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_e18728ed
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/addresses.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { getModelToken } from '@nestjs/mongoose';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { ProfilesService } from '../profiles/profiles.service';\nimport { AddressesService } from './addresses.service';\nimport { Address } from './schemas/address.schema';\n\nconst ProfileServiceProvider = {\n provide: ProfilesService,\n useFactory: () => ({}),\n};\n\ndescribe('AddressesService', () => {\n let service: AddressesService;\n\n beforeEach(async () => {\n const AddressModel = {\n provide: getModelToken(Address.name),\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n providers: [AddressesService, AddressModel, ProfileServiceProvider],\n }).compile();\n\n service = module.get<AddressesService>(AddressesService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_6fa66f86
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/addresses.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Body,\n Controller,\n Delete,\n Get,\n Param,\n Post,\n Query,\n UseGuards,\n UseInterceptors,\n Headers,\n} from '@nestjs/common';\nimport { TransformationTrim } from 'src/shared/transform/transformation-trim.pipe';\nimport { AuthGuard } from '../../../shared/guards/auth.guard';\nimport { MaskInterceptor } from '../../../shared/interceptors/mask.interceptor';\nimport { AddressesService } from './addresses.service';\nimport { CreateAddressDto } from './dtos/createAddress.dto';\nimport { ExternalAddressDto } from './dtos/externalAddress.dto';\n\n@Controller('/users/addresses')\nexport class AddressesController {\n constructor(private addressesService: AddressesService) {}\n\n @Post()\n create(@Body(new TransformationTrim()) createAddressDto: CreateAddressDto) {\n return this.addressesService.create(createAddressDto);\n }\n\n @Post('external')\n external(\n @Body() externalAddress: ExternalAddressDto,\n @Query('an') an: string,\n @Headers() headers,\n ) {\n return this.addressesService.external(\n externalAddress,\n an,\n headers.vtexidclientautcookie,\n );\n }\n\n @Get(':email')\n @UseInterceptors(MaskInterceptor)\n getAllByEmail(@Param('email') email, @Query('an') an: string) {\n return this.addressesService.findByEmail(email, an);\n }\n\n @Get('id/:id')\n get(@Param('id') id: string) {\n return this.addressesService.get(id);\n }\n\n @Delete(':id')\n @UseGuards(AuthGuard)\n async delete(@Param('id') id: string) {\n return this.addressesService.delete(id);\n }\n\n @Delete('/profile/:profileId')\n async deleteProfileAddresses(@Param('profileId') profileId: string) {\n return this.addressesService.deleteProfileAddresses(profileId);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_39558d8a
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/addresses.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { JwtService } from '@nestjs/jwt';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { ProfilesService } from '../profiles/profiles.service';\nimport { AddressesController } from './addresses.controller';\nimport { AddressesService } from './addresses.service';\n\nconst JwtServiceProvider = {\n provide: JwtService,\n useFactory: () => ({}),\n};\n\nconst ProfileServiceProvider = {\n provide: ProfilesService,\n useFactory: () => ({}),\n};\n\ndescribe('AddressesController', () => {\n let controller: AddressesController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: AddressesService,\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n controllers: [AddressesController],\n providers: [\n ApiServiceProvider,\n JwtServiceProvider,\n ProfileServiceProvider,\n ],\n }).compile();\n\n controller = module.get<AddressesController>(AddressesController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_aeb7f4a6
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/addresses.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus, Injectable } from '@nestjs/common';\nimport { AccountsService } from 'src/app/accounts/accounts.service';\nimport { ProfileSystemVTEXService } from 'src/app/vtex/profile-system/profile-system.service';\nimport { ApiResponse } from '../../../shared/responses';\nimport { ProfilesService } from '../profiles/profiles.service';\nimport { ProfileDoc } from '../profiles/schemas/profile.schema';\nimport { CreateAddressDto } from './dtos/createAddress.dto';\nimport { ExternalAddressDto } from './dtos/externalAddress.dto';\nimport { Address, AddressDoc, AddressModel } from './schemas/address.schema';\nimport { findBestMatch } from 'string-similarity';\nimport { GatewayException } from 'src/shared/exceptions/gateway-exception';\nimport { UsersService } from '../users.service';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { UserDoc } from '../schemas/user.schema';\nimport { GeoCoordinateDto } from './dtos/geoCoordinates.dto';\n\n@Injectable()\nexport class AddressesService {\n constructor(\n @InjectModel(Address.name) private addressModel: AddressModel,\n private profilesService: ProfilesService,\n private usersService: UsersService,\n private profileSystemVtexService: ProfileSystemVTEXService,\n private accountService: AccountsService,\n ) {}\n\n async create(createAddressDto: CreateAddressDto, isNew = false) {\n const profile = await this.profilesService.getById(\n createAddressDto.profileId,\n );\n\n if (!profile) {\n throw ApiResponse.error('errors.not_found', {}, HttpStatus.BAD_REQUEST);\n }\n\n let address: AddressDoc;\n\n if (createAddressDto.id && !isNew) {\n address = await this.addressModel.get(createAddressDto.id);\n if (!address) {\n address = this.addressModel.build({\n id: createAddressDto.id,\n state: createAddressDto.state,\n city: createAddressDto.city,\n country: createAddressDto.country,\n neighborhood: createAddressDto.neighborhood,\n street: createAddressDto.street,\n number: createAddressDto.number,\n postalCode: createAddressDto.postalCode,\n reference: createAddressDto.reference,\n receiverName: createAddressDto.receiverName,\n geoCoordinates: createAddressDto.geoCoordinates,\n profile,\n user: profile.user as UserDoc,\n });\n } else {\n address.set({\n state: createAddressDto.state,\n city: createAddressDto.city,\n country: createAddressDto.country,\n neighborhood: createAddressDto.neighborhood,\n street: createAddressDto.street,\n number: createAddressDto.number,\n postalCode: createAddressDto.postalCode,\n reference: createAddressDto.reference,\n receiverName: createAddressDto.receiverName,\n geoCoordinates: createAddressDto.geoCoordinates,\n profile,\n });\n }\n } else {\n address = this.addressModel.build({\n state: createAddressDto.state,\n city: createAddressDto.city,\n country: createAddressDto.country,\n neighborhood: createAddressDto.neighborhood,\n street: createAddressDto.street,\n number: createAddressDto.number,\n postalCode: createAddressDto.postalCode,\n reference: createAddressDto.reference,\n receiverName: createAddressDto.receiverName,\n geoCoordinates: createAddressDto.geoCoordinates,\n profile,\n user: profile.user as UserDoc,\n id: createAddressDto.id,\n });\n }\n\n try {\n await address.save();\n } catch (err) {\n console.log(err);\n throw new GatewayException('ADDRESS: Error creating address', err);\n }\n\n profile.set({\n selectedAddress: address.id,\n });\n\n await profile.save();\n\n address.profile = profile.id;\n\n return address;\n }\n\n async findByEmail(email: string, an: string) {\n const user = await this.usersService.getUserByEmail(email);\n const account = await this.accountService.get({ account: an });\n if (!user || !account) return [];\n const addresses = await this.addressModel.query({ user: user.id }).exec();\n return addresses.map((address) => this.addressModel.build(address));\n }\n\n get(id: string) {\n if (!id) return null;\n return this.addressModel.get(id);\n }\n\n async external(\n externalAddress: ExternalAddressDto,\n account: string,\n authToken: string,\n ) {\n let address: AddressDoc;\n const profile = await this.profilesService.getById(\n externalAddress.profileId,\n );\n\n if (!profile)\n throw ApiResponse.error('errors.not_found', {}, HttpStatus.BAD_REQUEST);\n\n if (externalAddress.addressId) {\n const headers = {\n VtexIdclientAutCookie: authToken,\n };\n const accountDoc = await this.accountService.get({ account });\n const addressVtex = await this.profileSystemVtexService.getUserAddress(\n accountDoc,\n profile,\n { addressName: externalAddress.addressId },\n headers,\n );\n if (addressVtex?.[0]) {\n const userAddresses = await this.addressModel\n .query({ profile: profile.id })\n .exec();\n\n const existAlternativeAddress = userAddresses.find(\n (alternativeAddress) =>\n alternativeAddress.id === addressVtex[0].addressName,\n );\n\n if (\n !existAlternativeAddress &&\n addressVtex[0].addressType === 'residential'\n ) {\n const newAddress: CreateAddressDto = {\n country: addressVtex[0].country as string,\n state: addressVtex[0].state as string,\n city: addressVtex[0].city as string,\n neighborhood: addressVtex[0].neighborhood as string,\n street: addressVtex[0].street as string,\n number: addressVtex[0].number as string,\n postalCode: addressVtex[0].postalCode as string,\n geoCoordinates: addressVtex[0].geoCoordinates as GeoCoordinateDto,\n id: addressVtex[0].addressName as string,\n profileId: addressVtex[0].profile.id as string,\n reference: addressVtex[0].reference as string,\n receiverName: addressVtex[0].receiverName as string,\n };\n\n address = await this.create(newAddress, true);\n } else if (addressVtex[0].addressType === 'residential') {\n address = existAlternativeAddress;\n }\n } else if (!externalAddress.postalCode.includes('*')) {\n const newAddress: CreateAddressDto = {\n country: externalAddress?.country,\n state: externalAddress?.state,\n city: externalAddress?.city,\n neighborhood: externalAddress?.neighborhood,\n street: externalAddress?.street,\n number: externalAddress?.number,\n postalCode: externalAddress.postalCode,\n geoCoordinates: externalAddress?.geoCoordinates,\n id: externalAddress?.addressId,\n profileId: externalAddress?.profileId,\n reference: externalAddress?.reference,\n receiverName: externalAddress?.receiverName,\n };\n\n address = await this.create(newAddress, true);\n }\n }\n\n return address?.id ? address : externalAddress;\n }\n\n // TODO: if it is the selected address by the user we should update it\n async delete(id: string) {\n const address = await this.addressModel.get(id);\n await address?.delete();\n return ApiResponse.send('responses.resource_deleted', address);\n }\n\n async deleteProfileAddresses(profileId: string) {\n const address = await this.addressModel\n .findOne({ profile: profileId })\n .exec();\n return address.delete();\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_89b41609
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/profiles/profiles.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { AccountsService } from '../../accounts/accounts.service';\nimport { ProfileSystemVTEXService } from '../../vtex/profile-system/profile-system.service';\nimport { ApiResponse } from '../../../shared/responses';\nimport { HttpStatus, Injectable } from '@nestjs/common';\nimport {\n Address,\n AddressDoc,\n AddressModel,\n} from '../addresses/schemas/address.schema';\nimport { Card, CardDoc, CardModel } from '../cards/schemas/cards.schema';\nimport { UserDoc } from '../schemas/user.schema';\nimport { UsersService } from '../users.service';\nimport { CreateProfileDto } from './dtos/createProfile.dto';\nimport { UpdateProfileDto } from './dtos/updateProfile.dto';\nimport { Profile, ProfileDoc, ProfileModel } from './schemas/profile.schema';\nimport { NotFoundException } from '../../../shared/exceptions/not-found-exception';\nimport { InjectModel } from 'nestjs-dynamoose';\n// import { AcceptanceHabeasDataService } from 'src/app/accounts/habeasData/acceptanceHabeasData/acceptanceHabeasData.service';\n// import { HabeasDataService } from 'src/app/accounts/habeasData/habeasData.service';\n\n@Injectable()\nexport class ProfilesService {\n constructor(\n @InjectModel(Profile.name) private profileModel: ProfileModel,\n @InjectModel(Address.name) private addressModel: AddressModel,\n @InjectModel(Card.name) private cardModel: CardModel,\n // private acceptanceHabeasDataService: AcceptanceHabeasDataService,\n private accountService: AccountsService,\n // private habeasDataService: HabeasDataService,\n private profileSystemVtexService: ProfileSystemVTEXService,\n private userService: UsersService,\n ) {}\n\n async getProfileInfo(email: string, account: string, headers: any) {\n let user = await this.userService.getUserByEmail(email);\n\n const profiles = user\n ? await this.profileModel\n .query({\n user: user.id,\n })\n .exec()\n : null;\n\n if (!profiles || profiles.count === 0) {\n const accountDoc = await this.accountService.get({ account });\n const userVtex = await this.profileSystemVtexService.getUserInfo(\n accountDoc,\n email,\n headers,\n );\n\n if (\n userVtex &&\n userVtex.name &&\n userVtex.lastname &&\n userVtex.phoneNumber &&\n userVtex.documentType &&\n userVtex.document\n ) {\n if (!user) {\n user = await this.userService.create({\n email,\n account,\n });\n }\n const profile = this.profileModel.build({\n name: userVtex.name,\n lastname: userVtex.lastname,\n phoneCode: '+57',\n phoneNumber: userVtex.phoneNumber,\n documentType: userVtex.documentType,\n document: userVtex.document,\n user,\n account: accountDoc,\n habeasData: false,\n creationDate: new Date().toISOString(),\n });\n await profile.save();\n const addressesVtex =\n await this.profileSystemVtexService.getUserAddress(\n accountDoc,\n profile,\n { userId: userVtex.id },\n headers,\n );\n\n addressesVtex?.map((addressVtex) => {\n return {\n country: addressVtex.country,\n state: addressVtex.state,\n city: addressVtex.city,\n neighborhood: addressVtex.neighborhood,\n street: addressVtex.street,\n number: addressVtex.number,\n postalCode: addressVtex.postalCode,\n geoCoordinates: addressVtex.geoCoordinates,\n id: addressVtex.addressName,\n profileId: addressVtex.profile.id,\n reference: addressVtex.reference,\n receiverName: addressVtex.receiverName,\n };\n });\n\n const addresses = await this.addressModel.insertMany(addressesVtex);\n\n addresses?.forEach((address) => {\n address.profile = profile.id;\n });\n\n if (addresses && addresses.length > 0) {\n delete addresses[0].profile;\n profile.set({\n selectedAddress: addresses[0],\n });\n\n await profile.save();\n\n profile.addresses = addresses.map((address) => {\n delete address.profile;\n return this.addressModel.build(address);\n });\n profile.selectedAddress = this.addressModel.build(\n profile.selectedAddress as AddressDoc,\n );\n }\n\n profile.email = email;\n\n return profile;\n }\n throw new NotFoundException('user does not exist');\n }\n\n const cards = await this.cardModel\n .query({\n user: user.id,\n })\n .where('profile')\n .in(profiles.map((p) => p.id))\n .exec();\n\n const addresses = await this.addressModel\n .query({\n user: user.id,\n })\n .where('profile')\n .in(profiles.map((p) => p.id))\n .exec();\n\n // const habeasData = await this.habeasDataService.getByActiveState();\n\n // const acceptanceHabeasData =\n // await this.acceptanceHabeasDataService.getByEmail(\n // email,\n // habeasData.version,\n // );\n\n const profile = this.profileModel.build(profiles[0]);\n\n // if (habeasData)\n // profile.habeasData = habeasData.version === acceptanceHabeasData?.version;\n\n if (profile.selectedAddress) {\n await profile.populate({\n properties: 'selectedAddress',\n });\n }\n profile.addresses = addresses;\n profile.cards = cards;\n if (profile.selectedPayment?.card) {\n if (\n cards.find(\n (card) => card.id === profile.selectedPayment.card.toString(),\n )\n ) {\n await profile.populate({\n properties: 'selectedPayment.card',\n });\n } else delete profile.selectedPayment;\n }\n profile.email = email;\n\n return profile;\n }\n\n async create(createProfileDto: CreateProfileDto, an: string) {\n const account = await this.accountService.get({ account: an });\n // const habeasData = await this.habeasDataService.getByActiveState();\n\n if (!account) {\n throw ApiResponse.error('errors.not_found', {}, HttpStatus.BAD_REQUEST);\n }\n\n let user: UserDoc = await this.userService.getUserByEmail(\n createProfileDto.email,\n );\n\n if (!user) {\n user = await this.userService.create({\n email: createProfileDto.email,\n account: an,\n });\n }\n\n let profile: ProfileDoc = await this.profileModel\n .findOne({ user: user.id })\n .exec();\n\n const profileDto = {\n name: createProfileDto.name,\n lastname: createProfileDto.lastname,\n document: createProfileDto.id_number,\n documentType: createProfileDto.id_type,\n phoneCode: createProfileDto.phone_code,\n phoneNumber: createProfileDto.phone_number,\n user,\n account,\n habeasData: createProfileDto.habeasData,\n creationDate: new Date().toISOString(),\n };\n\n if (!profile) profile = this.profileModel.build(profileDto);\n else profile.set(profileDto);\n\n await profile.save();\n\n profile.email = user.email;\n\n // if (profile && profile.habeasData && createProfileDto.ip) {\n // const acceptanceHabeasDataSave = {\n // document: createProfileDto.id_number,\n // documentType: createProfileDto.id_type,\n // email: user.email,\n // ip: createProfileDto?.ip,\n // url: habeasData.url,\n // version: habeasData.version,\n // };\n\n // this.acceptanceHabeasDataService.create(acceptanceHabeasDataSave);\n // }\n\n return profile;\n }\n\n async update(\n profile: ProfileDoc,\n account: string,\n updateProfileDto: UpdateProfileDto,\n authToken: string,\n ) {\n let selectedPayment: { paymentMethod: string; card: string | CardDoc };\n const headers = {\n VtexIdclientAutCookie: authToken,\n };\n if (updateProfileDto.selectedPayment) {\n if (updateProfileDto.selectedPayment === 'promissory') {\n selectedPayment = {\n paymentMethod: 'promissory',\n card: null,\n };\n } else {\n selectedPayment = {\n paymentMethod: 'tc',\n card: updateProfileDto.selectedPayment,\n };\n }\n } else selectedPayment = profile.selectedPayment;\n delete updateProfileDto.email;\n profile.set({\n ...updateProfileDto,\n selectedPayment,\n });\n\n await profile.save();\n return ApiResponse.send(\n 'responses.resource_updated',\n await this.getProfileInfo(profile.email, account, headers),\n );\n }\n\n getById(id: string) {\n return this.profileModel.get(id);\n }\n\n getByUserAccount(user: UserDoc) {\n return this.profileModel.query({ user: user.id }).exec();\n }\n\n async getByPhone(countryCode: number, number: number) {\n const profiles = await this.profileModel\n .query({ phoneNumber: `${number}` })\n .where('phoneCode')\n .eq(`+${countryCode}`)\n .exec();\n const emails = profiles.map((prof) =>\n this.userService.getUserById(prof?.user.toString()),\n );\n return Promise.all(emails);\n }\n\n async getByEmail(email: string) {\n const user = await this.userService.getUserByEmail(email);\n\n const profile = await this.profileModel\n .query({\n user: user.id,\n })\n .exec();\n\n return profile;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_b24ad454
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/profiles/profiles.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Body,\n Controller,\n Get,\n Inject,\n Param,\n Post,\n Put,\n Query,\n UseGuards,\n UseInterceptors,\n Headers,\n} from '@nestjs/common';\nimport { REQUEST } from '@nestjs/core';\nimport { TransformationTrim } from 'src/shared/transform/transformation-trim.pipe';\nimport { AuthGuard } from '../../../shared/guards/auth.guard';\nimport { MaskInterceptor } from '../../../shared/interceptors/mask.interceptor';\nimport { CreateProfileDto } from './dtos/createProfile.dto';\nimport { UpdateProfileDto } from './dtos/updateProfile.dto';\nimport { ProfilesService } from './profiles.service';\n\n@Controller('/users/profiles')\nexport class ProfilesController {\n constructor(\n @Inject(REQUEST) protected readonly request: any,\n private profilesService: ProfilesService,\n ) {}\n\n @Get(':email')\n @UseInterceptors(MaskInterceptor)\n getProfileInfo(\n @Param('email') email: string,\n @Query('an') an: string,\n @Headers() header,\n ) {\n return this.profilesService.getProfileInfo(email, an, {\n VtexIdclientAutCookie: header.vtexidclientautcookie,\n });\n }\n\n @Post(`/phone`)\n @UseInterceptors(MaskInterceptor)\n getUserByPhone(\n @Body('countryCode') countryCode: number,\n @Body('number') number: number,\n ) {\n return this.profilesService.getByPhone(countryCode, number);\n }\n\n @Post()\n create(\n @Body(new TransformationTrim()) createProfileDto: CreateProfileDto,\n @Query('an') an: string,\n ) {\n return this.profilesService.create(createProfileDto, an);\n }\n\n @Put()\n @UseGuards(AuthGuard)\n update(\n @Body(new TransformationTrim()) updateProfileDto: UpdateProfileDto,\n @Headers() header,\n ) {\n return this.profilesService.update(\n this.request.user,\n this.request.account,\n updateProfileDto,\n header.vtexidclientautcookie,\n );\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_f1ec7a21
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/profiles/profiles.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { REQUEST } from '@nestjs/core';\nimport { JwtService } from '@nestjs/jwt';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { ProfilesController } from './profiles.controller';\nimport { ProfilesService } from './profiles.service';\n\nconst JwtServiceProvider = {\n provide: JwtService,\n useFactory: () => ({}),\n};\n\ndescribe('ProfilesController', () => {\n let controller: ProfilesController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: ProfilesService,\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n controllers: [ProfilesController],\n providers: [\n ApiServiceProvider,\n JwtServiceProvider,\n {\n provide: REQUEST,\n useValue: {},\n },\n ],\n }).compile();\n\n controller = module.get<ProfilesController>(ProfilesController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_ab549129
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/profiles/profiles.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { getModelToken } from '@nestjs/mongoose';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { AccountsLinksService } from '../../accounts/accounts-links/accounts-links.service';\nimport { AccountsService } from '../../accounts/accounts.service';\nimport { ProfileSystemVTEXService } from '../../vtex/profile-system/profile-system.service';\nimport { Address } from '../addresses/schemas/address.schema';\nimport { Card } from '../cards/schemas/cards.schema';\nimport { UsersService } from '../users.service';\nimport { ProfilesService } from './profiles.service';\nimport { Profile } from './schemas/profile.schema';\n\nconst ProfileModel = {\n provide: getModelToken(Profile.name),\n useFactory: () => ({}),\n};\nconst AddressModel = {\n provide: getModelToken(Address.name),\n useFactory: () => ({}),\n};\nconst CardModel = {\n provide: getModelToken(Card.name),\n useFactory: () => ({}),\n};\nconst UserServiceProvider = {\n provide: UsersService,\n useFactory: () => ({}),\n};\nconst AccountServiceProvider = {\n provide: AccountsService,\n useFactory: () => ({}),\n};\nconst AccountLinkServiceProvider = {\n provide: AccountsLinksService,\n useFactory: () => ({}),\n};\nconst VtexProfileSystemServiceProvider = {\n provide: ProfileSystemVTEXService,\n useFactory: () => ({}),\n};\n\ndescribe('ProfilesService', () => {\n let service: ProfilesService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [\n ProfilesService,\n ProfileModel,\n AddressModel,\n CardModel,\n UserServiceProvider,\n AccountServiceProvider,\n AccountLinkServiceProvider,\n VtexProfileSystemServiceProvider,\n ],\n }).compile();\n\n service = module.get<ProfilesService>(ProfilesService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_4884ae54
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/auth/schemas/auth.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\nimport * as bcrypt from 'bcrypt';\nimport { PasswordCodes } from '../dtos/password_codes.enum';\n\nconst maxAttempts = 3;\nconst dueTime = 600000;\nconst loginTime = 60000;\nconst validateTime = 600000;\n\ninterface AuthAttrs {\n email: string;\n}\n\nexport interface AuthDoc extends Document {\n email: string;\n password: string;\n attempts: number;\n validateLockedUntil: number;\n dueDate: number;\n loginLockedUntil: number;\n isLocked(): boolean;\n validatePassword(password: string): Promise<PasswordCodes>;\n isLockedValidate(): boolean;\n}\n\nexport interface AuthModel extends Model<AuthDoc, AuthAttrs> {\n generatePassword(): string;\n}\n\nconst AuthSchema = Schema.build({\n password: {\n type: String,\n required: true,\n set: async (password, old?) => {\n if (password !== old) {\n const salt = await bcrypt.genSalt();\n return await bcrypt.hash(password, salt);\n }\n return password;\n },\n },\n attempts: { type: Number, required: true, default: 0 },\n dueDate: {\n type: Number,\n required: true,\n default: () => Date.now() + dueTime,\n },\n loginLockedUntil: {\n type: Number,\n required: true,\n default: () => Date.now() + loginTime,\n },\n validateLockedUntil: Number,\n email: {\n type: String,\n required: true,\n index: { global: true, name: 'emailIndex' },\n },\n});\n\nexport const Auth: ModelDefinition = {\n name: 'authentications',\n schema: AuthSchema,\n methods: {\n transform: (ret: AuthDoc) => {\n delete ret.password;\n },\n isLocked: function () {\n return Date.now() < this.loginLockedUntil || this.isLockedValidate();\n },\n isLockedValidate: function () {\n return Date.now() < this.validateLockedUntil;\n },\n validatePassword: async function (password: string) {\n if (this.isLockedValidate()) return PasswordCodes.locked;\n if (Date.now() > this.dueDate) return PasswordCodes.expired;\n this.attempts += 1;\n if (this.attempts >= maxAttempts) {\n this.attempts = 1;\n this.validateLockedUntil = Date.now() + validateTime;\n }\n if (await bcrypt.compareSync(password, this.password))\n return PasswordCodes.valid;\n return PasswordCodes.invalid;\n },\n },\n statics: {\n generatePassword: () => {\n return String(Math.floor(100000 + Math.random() * 900000));\n },\n },\n};\n\n```" } ]
code_mycheckout-checkout-service_b38ec1aa
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/auth/dtos/password_codes.enum.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport enum PasswordCodes {\n 'expired' = 'expired_code',\n 'locked' = 'locked_action',\n 'valid' = 'valid_code',\n 'invalid' = 'invalid_code',\n}\n\n```" } ]
code_mycheckout-checkout-service_145dc860
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/auth/dtos/odt.code.data.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport const ODTCodeData = {\n TemplateName: 'vtexid_check_email',\n JsonData: {\n to: [\n {\n name: '',\n email: '',\n },\n ],\n aditionalData: {\n accessKey: '',\n locale: 'es',\n userAgent: 'Chrome, Mac OS X',\n geolocation: {\n country: 'Colombia',\n region: 'DC',\n city: 'Bogot�',\n ip: '186.80.52.72',\n },\n },\n _accountInfo: {\n MainAccountName: 'vtexlatam',\n AccountName: 'vtexlatam',\n Cnpj: '99999999999999',\n Id: '57703872-29ef-4b3d-a728-8a4ca67b69f0',\n IsActive: true,\n IsOperating: true,\n CreationDate: '2014-08-22T00:00:00',\n OperationDate: '2020-06-02T22:49:43',\n CompanyName: 'VTEX LATAM',\n TradingName: 'VTEX LATAM',\n City: null,\n Complement: null,\n Country: null,\n State: null,\n Address: null,\n District: null,\n Number: null,\n PostalCode: null,\n Licences: null,\n ParentAccountName: null,\n InactivationDate: null,\n Platform: 'vtex',\n },\n },\n};\n\n```" } ]
code_mycheckout-checkout-service_26505b7c
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/cards/schemas/cards.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\nimport { Profile, ProfileDoc } from '../../profiles/schemas/profile.schema';\nimport { User, UserDoc } from '../../schemas/user.schema';\n\nenum franchise {\n 'vi' = 'visa',\n 'visa' = 'vi',\n 'mc' = 'master',\n 'master' = 'master',\n 'di' = 'diner',\n 'diner' = 'diner',\n 'amex' = 'amex',\n}\n\ninterface CardAttrs {\n franchise: string;\n number: string;\n token?: string;\n gateway: string;\n profile: ProfileDoc;\n user: UserDoc;\n bin?: string;\n cvv?: string;\n holderName?: string;\n holderDocument?: string;\n expirationDate?: string;\n cardNumber?: string;\n aliasCC?: string;\n aliasCVV?: string;\n accountId?: string;\n paymentSystem?: string;\n cardContent?: Record<string, any>;\n internalCardContent?: Record<string, any>;\n}\n\nexport interface CardDoc extends Document {\n franchise: string;\n number: string;\n token?: string;\n gateway: string;\n profile: ProfileDoc;\n user: UserDoc;\n bin?: string;\n cvv?: string;\n holderName?: string;\n holderDocument?: string;\n expirationDate?: string;\n aliasCC?: string;\n aliasCVV?: string;\n accountId?: string;\n cardNumber?: string;\n paymentSystem?: string;\n cardContent?: Record<string, any>;\n internalCardContent?: Record<string, any>;\n}\n\nexport type CardModel = Model<CardDoc, CardAttrs>;\n\nexport const CardSchema = Schema.build({\n franchise: { type: String, required: true },\n number: { type: String, required: true },\n token: { type: String },\n gateway: { type: String, required: true },\n bin: { type: String },\n cvv: { type: String },\n paymentSystem: { type: String },\n holderName: { type: String },\n holderDocument: { type: String },\n expirationDate: { type: String },\n cardNumber: { type: String },\n aliasCC: { type: String },\n aliasCVV: { type: String },\n accountId: { type: String },\n cardContent: Object,\n internalCardContent: Object,\n});\n\nexport const Card: ModelDefinition = {\n name: 'cards',\n schema: CardSchema,\n methods: {\n transform: (ret: CardDoc) => {\n ret.franchise = franchise[ret.franchise];\n ret.cvv = ret.token ? 'required' : 'non-required';\n delete ret.token;\n delete ret.internalCardContent;\n //delete ret.cvv;\n delete ret.holderName;\n delete ret.holderDocument;\n delete ret.cardNumber;\n delete ret.expirationDate;\n delete ret.aliasCC;\n delete ret.aliasCVV;\n },\n },\n population: function (populate) {\n this.schema.schemaObject.profile = {\n type: populate(Profile),\n index: { global: true, name: 'profileIndex' },\n };\n this.schema.schemaObject.user = {\n type: populate(User),\n index: { global: true, name: 'userIndex' },\n };\n },\n};\n\n/*\n@Prop({\n required: true,\n type: mongoose.Schema.Types.ObjectId,\n ref: 'Profile',\n})\nprofile: null; //Profile;\n\n\n@Prop({ required: false, type: {} })\ncardContent: Record<string, any>;\n\n\n @Prop({ required: false, type: {} })\n internalCardContent: Record<string, any>;*/\n\n```" } ]
code_mycheckout-checkout-service_95506e3e
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/cards/dtos/card.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport class CardDto {\n token?: string;\n franchise: string;\n number: string;\n gateway: string;\n bin?: string;\n holderName?: string;\n holderDocument?: string;\n cvv?: string;\n expirationDate?: string;\n cardNumber?: string;\n aliasCC?: string;\n aliasCVV?: string;\n cardContent?: unknown;\n paymentSystem?: string;\n internalCardContent?: unknown;\n}\n\n```" } ]
code_mycheckout-checkout-service_84e370d5
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/schemas/address.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\nimport { maskPhone as maskString } from 'maskdata';\nimport { Profile, ProfileDoc } from '../../profiles/schemas/profile.schema';\nimport { UserDoc } from '../../schemas/user.schema';\n\nexport interface AddressAttrs {\n country: string;\n state: string;\n city: string;\n neighborhood: string;\n street: string;\n number: string;\n postalCode: string;\n reference: string;\n receiverName: string;\n geoCoordinates: {\n longitude: string;\n latitude: string;\n };\n profile: ProfileDoc;\n user: UserDoc;\n id?: string;\n}\n\nexport interface AddressDoc extends Document {\n country: string;\n state: string;\n city: string;\n neighborhood: string;\n street: string;\n number: string;\n postalCode: string;\n reference: string;\n receiverName: string;\n geoCoordinates: {\n longitude: string;\n latitude: string;\n };\n addressId?: string;\n profile: ProfileDoc | ProfileDoc['id'];\n user: UserDoc;\n isEqual?: boolean;\n mask(this: this): this;\n}\n\nexport type AddressModel = Model<AddressDoc, AddressAttrs>;\n\nexport const AddressSchema = Schema.build({\n country: { type: String, required: true },\n state: { type: String, required: true },\n city: { type: String, required: true },\n neighborhood: { type: String, required: true },\n street: { type: String, required: true },\n number: { type: String, required: true },\n postalCode: { type: String },\n reference: { type: String },\n receiverName: { type: String, required: true },\n geoCoordinates: {\n type: Object,\n schema: {\n longitude: { type: String, required: true },\n latitude: { type: String, required: true },\n },\n },\n});\n\nexport const Address: ModelDefinition = {\n name: 'addresses',\n schema: AddressSchema,\n methods: {\n mask: function (this: AddressDoc) {\n this.country = maskString(this.country, { unmaskedStartDigits: 3 });\n this.city = maskString(this.city, { unmaskedStartDigits: 3 });\n this.state = maskString(this.state, { unmaskedStartDigits: 3 });\n this.street = maskString(this.street, { unmaskedStartDigits: 3 });\n this.number = maskString(this.number, { unmaskedStartDigits: 3 });\n this.receiverName = maskString(this.receiverName, {\n unmaskedStartDigits: 3,\n });\n this.geoCoordinates = { longitude: '', latitude: '' };\n this.neighborhood = maskString(\n this.neighborhood ? this.neighborhood : '',\n {\n unmaskedStartDigits: 3,\n },\n );\n this.reference = maskString(this.reference ? this.reference : '', {\n unmaskedStartDigits: 3,\n });\n return this;\n },\n },\n population: function (populate) {\n this.schema.schemaObject.profile = {\n type: populate(Profile),\n index: { global: true, name: 'profileIndex' },\n };\n this.schema.schemaObject.user = {\n type: populate(Profile),\n index: { global: true, name: 'userIndex' },\n };\n },\n};\n\n```" } ]
code_mycheckout-checkout-service_9425d7c9
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/dtos/externalAddress.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { GeoCoordinateDto } from './geoCoordinates.dto';\n\nexport class ExternalAddressDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n addressId?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n country?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n state?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n city?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n neighborhood?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n street?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n number?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n postalCode?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n reference?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n receiverName?: string;\n\n @IsOptional()\n @ValidateNested()\n geoCoordinates: GeoCoordinateDto;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n profileId: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_462769a0
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/dtos/createAddress.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { GeoCoordinateDto } from './geoCoordinates.dto';\n\nexport class CreateAddressDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n id?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n country: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n state: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n city: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n neighborhood: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n street: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n number: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n postalCode: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n reference?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n receiverName: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n geoCoordinates: GeoCoordinateDto;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n profileId: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_8b09c0ab
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/addresses/dtos/geoCoordinates.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsLatitude,\n IsLongitude,\n IsNotEmpty,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses/api-error';\n\nexport class GeoCoordinateDto {\n /*amount arg*/\n //validations\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsLatitude({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_latitude', args),\n })\n //field\n latitude: string;\n\n /*longitude arg*/\n //validations\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsLongitude({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_longitude', args),\n })\n //field\n longitude: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_41b6810b
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/profiles/schemas/profile.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\nimport { User, UserDoc } from '../../schemas/user.schema';\nimport { Account, AccountDoc } from '../../../accounts/schemas/account.schema';\nimport { Address, AddressDoc } from '../../addresses/schemas/address.schema';\nimport { maskPhone, maskCard, maskString } from 'maskdata';\nimport { Card, CardDoc } from '../../cards/schemas/cards.schema';\n\nexport interface ProfileAttrs {\n name: string;\n lastname: string;\n documentType: string;\n document: string;\n phoneCode: string;\n phoneNumber: string;\n user: UserDoc;\n account: AccountDoc;\n habeasData: boolean;\n creationDate: string;\n}\n\nexport interface ProfileDoc extends Document {\n email?: string;\n name: string;\n lastname: string;\n documentType: string;\n document: string;\n phoneCode: string;\n phoneNumber: string;\n user: UserDoc | UserDoc['id'];\n account: AccountDoc;\n habeasData: boolean;\n selectedAddress: AddressDoc | AddressDoc['id'];\n selectedPayment: {\n paymentMethod: string;\n card: CardDoc | CardDoc['id'];\n };\n addresses: AddressDoc[];\n cards: CardDoc[];\n creationDate: string;\n version: number;\n mask(this: this): this;\n}\n\nexport type ProfileModel = Model<ProfileDoc, ProfileAttrs>;\n\nexport const ProfileSchema = Schema.build({\n name: { type: String, required: true },\n lastname: { type: String, required: true },\n documentType: { type: String },\n document: { type: String, required: true },\n phoneCode: { type: String, default: '' },\n phoneNumber: {\n type: String,\n required: true,\n index: { global: true, name: 'phoneNumberIndex' },\n },\n habeasData: { type: Boolean, required: true, default: false },\n creationDate: { type: String },\n});\n\nexport const Profile: ModelDefinition = {\n name: 'profiles',\n schema: ProfileSchema,\n methods: {\n transform: (ret: ProfileDoc) => {\n // delete ret.user;\n delete ret.account;\n delete ret.creationDate;\n ret['phone_code'] = ret.phoneCode;\n ret['phone_number'] = ret.phoneNumber;\n ret['id_type'] = ret.documentType;\n ret['id_number'] = ret.document;\n\n /*if (doc.email) {\n ret.email = doc.email;\n }\n if (doc.cards) {\n ret.cards = doc.cards;\n }*/\n },\n mask: function (this: ProfileDoc) {\n this.phoneNumber = maskPhone(this.phoneNumber);\n this.document = maskCard(this.document);\n this.name = maskString(this.name, { maskAll: true });\n this.lastname = maskString(this.lastname, { maskAll: true });\n this.addresses?.map((address) => {\n return address.mask();\n });\n (this.selectedAddress as AddressDoc)?.mask();\n\n return this;\n },\n },\n population: function (populate) {\n this.schema.schemaObject.user = {\n type: populate(User),\n index: { global: true, name: 'userIndex' },\n };\n this.schema.schemaObject.account = {\n type: populate(Account),\n index: { global: true, name: 'accountIndex' },\n };\n this.schema.schemaObject.selectedAddress = {\n type: populate(Address),\n index: { global: true, name: 'selectedAddressIndex' },\n };\n this.schema.schemaObject.selectedPayment = {\n type: Object,\n schema: {\n paymentMethod: { type: String },\n card: {\n type: populate(Card),\n index: { global: true, name: 'cardIndex' },\n },\n },\n };\n },\n};\n\n```" } ]
code_mycheckout-checkout-service_5f49e03d
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/profiles/dtos/createProfile.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsBoolean,\n IsEmail,\n IsMobilePhone,\n IsNotEmpty,\n IsOptional,\n IsString,\n MaxLength,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\n\nexport class CreateProfileDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n name: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n lastname: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n id_type: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @MaxLength(30, {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_greater', args),\n })\n id_number: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsEmail(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_email', args),\n },\n )\n readonly email: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n phone_code: string;\n\n @IsMobilePhone(null, null, {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_phone', args),\n })\n phone_number: string;\n\n @IsBoolean({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n habeasData: boolean;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n ip: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_b626b1d5
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/users/profiles/dtos/updateProfile.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsBoolean,\n IsEmail,\n IsMobilePhone,\n IsOptional,\n IsString,\n MaxLength,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\n\nexport class UpdateProfileDto {\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n name?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n lastname?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id_type?: string;\n\n @IsOptional()\n @MaxLength(30, {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_greater', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id_number?: string;\n\n @IsOptional()\n @IsEmail(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_email', args),\n },\n )\n email?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n phone_code?: string;\n\n @IsOptional()\n @IsMobilePhone(null, null, {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_phone', args),\n })\n phone_number?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n selectedAddress: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n selectedPayment: string;\n\n @IsBoolean({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n habeasData: boolean;\n}\n\n```" } ]
code_mycheckout-checkout-service_815c4780
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/cities/cities.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { getModelToken } from 'nestjs-dynamoose';\nimport { CitiesService } from './cities.service';\nimport { City } from './schemas/city.schema';\n\ndescribe('CitiesService', () => {\n let service: CitiesService;\n\n beforeEach(async () => {\n const CityModel = {\n provide: getModelToken(City.name),\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n providers: [CitiesService, CityModel],\n }).compile();\n\n service = module.get<CitiesService>(CitiesService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_76e41c99
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/cities/cities.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Body, Controller, Get, Post } from '@nestjs/common';\nimport { CitiesService } from './cities.service';\nimport { CitiesDto } from './dtos/cities.dto';\nimport { CityDto } from './dtos/city.dto';\n\n@Controller('masters/cities')\nexport class CitiesController {\n constructor(private citiesService: CitiesService) {}\n\n @Get()\n getAll() {\n return this.citiesService.getAll();\n }\n\n @Get()\n getCity(city: string) {\n return this.citiesService.getCity(city);\n }\n\n @Post('many')\n createMany(@Body() createCitiesDto: CitiesDto) {\n return this.citiesService.createMany(createCitiesDto);\n }\n\n @Post('')\n create(@Body() createCityDto: CityDto) {\n return this.citiesService.create(createCityDto);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_7c90ec00
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/cities/cities.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { diacriticSensitive } from 'src/shared/utils/diacritic-sensitive';\nimport { CitiesDto } from './dtos/cities.dto';\nimport { CityDto } from './dtos/city.dto';\nimport { City, CityModel } from './schemas/city.schema';\n\n@Injectable()\nexport class CitiesService {\n private transaction: { transaction: any; '': any };\n constructor(@InjectModel(City.name) private cityModel: CityModel) {\n this.transaction = {\n transaction: this.cityModel.transaction,\n '': this.cityModel,\n };\n }\n\n getAll() {\n return this.cityModel.scan().exec();\n }\n\n getCity(city: string) {\n return this.cityModel\n .scan({\n citySearch: { contains: diacriticSensitive(city.toLowerCase()) },\n })\n .exec();\n }\n\n create(createCityDto: CityDto, trans: keyof typeof this.transaction = '') {\n return this.transaction[trans].create(createCityDto);\n }\n\n createMany(createCityDto: CitiesDto) {\n return this.cityModel.insertMany(createCityDto.cities);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_513a9a24
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/cities/cities.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CitiesController } from './cities.controller';\nimport { CitiesService } from './cities.service';\n\ndescribe('CitiesController', () => {\n let controller: CitiesController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: CitiesService,\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n controllers: [CitiesController],\n providers: [ApiServiceProvider],\n }).compile();\n\n controller = module.get<CitiesController>(CitiesController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_856b34e3
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/countries/countries.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { transaction } from 'dynamoose';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { splitArrayIntoChunksOfLen } from 'src/shared/utils/data-array';\nimport { diacriticSensitive } from '../../../shared/utils/diacritic-sensitive';\nimport { CitiesService } from '../cities/cities.service';\nimport { CountriesDto } from './dtos/countries.dto';\nimport { Country, CountryModel } from './schemas/country.schema';\n\n@Injectable()\nexport class CountriesService {\n constructor(\n @InjectModel(Country.name) private countryModel: CountryModel,\n protected citiesService: CitiesService,\n ) {}\n\n getAll() {\n return this.countryModel.scan().exec();\n }\n\n async create(createCountriesDto: CountriesDto) {\n const transactions = [];\n const countries = createCountriesDto.countries.map((country) => {\n const states = [];\n Object.entries(country.states).forEach(([state, c]) => {\n const cities = [];\n Object.entries(c).forEach(([city, postalCode]) => {\n cities.push({\n city: city,\n city_id: postalCode,\n });\n transactions.push(\n this.citiesService.create(\n {\n city: city,\n citySearch: diacriticSensitive(city.toLowerCase()),\n state: state,\n stateSearch: diacriticSensitive(state.toLowerCase()),\n country: country.country,\n countrySearch: diacriticSensitive(\n country.country.toLowerCase(),\n ),\n phone: country.phone,\n iso: country.iso,\n postal_code: postalCode,\n },\n 'transaction',\n ),\n );\n });\n states.push({ state: state, cities: cities });\n });\n country.states = states;\n transactions.push(this.countryModel.transaction.create(country));\n return country;\n });\n await Promise.all(splitArrayIntoChunksOfLen(transactions, 25, transaction));\n return countries;\n }\n\n async delete(id: string) {\n return (await this.countryModel.get(id))?.delete();\n }\n\n async getCities(city) {\n return this.citiesService.getCity(city);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_8540c7c7
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/countries/countries.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CountriesController } from './countries.controller';\nimport { CountriesService } from './countries.service';\n\ndescribe('CountriesController', () => {\n let controller: CountriesController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: CountriesService,\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n controllers: [CountriesController],\n providers: [ApiServiceProvider],\n }).compile();\n\n controller = module.get<CountriesController>(CountriesController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_e11bf961
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/countries/countries.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { getModelToken } from 'nestjs-dynamoose';\nimport { CountriesService } from './countries.service';\nimport { Country } from './schemas/country.schema';\n\ndescribe('CountriesService', () => {\n let service: CountriesService;\n\n beforeEach(async () => {\n const CountryModel = {\n provide: getModelToken(Country.name),\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n providers: [CountriesService, CountryModel],\n }).compile();\n\n service = module.get<CountriesService>(CountriesService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_a1bd9006
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/countries/countries.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Body,\n Controller,\n Get,\n Post,\n Query,\n Delete,\n Param,\n} from '@nestjs/common';\nimport { CountriesService } from './countries.service';\nimport { CountriesDto } from './dtos/countries.dto';\n\n@Controller('masters/countries')\nexport class CountriesController {\n constructor(private countriesService: CountriesService) {}\n\n @Get()\n getAll() {\n return this.countriesService.getAll();\n }\n\n @Post()\n create(@Body() createCountriesDto: CountriesDto) {\n return this.countriesService.create(createCountriesDto);\n }\n\n @Delete(':id')\n delete(@Param('id') id: string) {\n return this.countriesService.delete(id);\n }\n\n @Get('cities')\n async cities(@Query('city') city: string): Promise<any> {\n return this.countriesService.getCities(city.trim());\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_374b5b81
[ { "role": "system", "content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms." }, { "role": "user", "content": "Show me the implementation of mycheckout-checkout-service/src/app/masters/document-types/document-types.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { getModelToken } from 'nestjs-dynamoose';\nimport { DocumentTypesService } from './document-types.service';\nimport { DocumentType } from './schemas/document-type.schema';\n\ndescribe('DocumentTypesService', () => {\n let service: DocumentTypesService;\n\n beforeEach(async () => {\n const DocumentTypeModel = {\n provide: getModelToken(DocumentType.name),\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n providers: [DocumentTypesService, DocumentTypeModel],\n }).compile();\n\n service = module.get<DocumentTypesService>(DocumentTypesService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]