#StorePostCustomersCustomerReq to allow custom fields

7 messages · Page 1 of 1 (latest)

harsh elk
#

Hi aymen,
Can you share the whole file of your extended validators please ?

torn quartz
#

import { registerOverriddenValidators } from '@medusajs/medusa'
import { StorePostCustomersReq as MedusaStorePostCustomersReq } from '@medusajs/medusa/dist/api/routes/store/customers/create-customer'
import { IsString } from 'class-validator'

class StorePostCustomersReq extends MedusaStorePostCustomersReq {
@IsString()
company_name?: string

@IsString()
store_name?: string

@IsString()
vat?: string
}

registerOverriddenValidators(StorePostCustomersReq)

#

hey, thanks for your reply! here's the code to extend the validator

#

i can retrieve the data but it just won't let me update them

#

i've extended the StorePostCustomersCustomerReq class as well:

import { registerOverriddenValidators } from '@medusajs/medusa'
import { StorePostCustomersReq as MedusaStorePostCustomersReq } from '@medusajs/medusa/dist/api/routes/store/customers/create-customer'
import { StorePostCustomersCustomerReq as MedusaStorePostCustomersCustomerReq } from '@medusajs/medusa/dist/api/routes/store/customers/update-customer'

import { IsString } from 'class-validator'

class StorePostCustomersReq extends MedusaStorePostCustomersReq {
  @IsString()
  company_name?: string

  @IsString()
  store_name?: string

  @IsString()
  vat?: string
}

// Extend the request type for customer updates
class StorePostCustomersCustomerReq extends MedusaStorePostCustomersCustomerReq {
  @IsString()
  company_name?: string

  @IsString()
  store_name?: string

  @IsString()
  vat?: string
}

// Register the overridden validators
registerOverriddenValidators(StorePostCustomersReq)
registerOverriddenValidators(StorePostCustomersCustomerReq)
#

but now i get Response data: {
type: 'invalid_data',
message: 'store_name must be a string, vat must be a string'
}

#

if i just include the company_name here it works fine

class StorePostCustomersCustomerReq extends MedusaStorePostCustomersCustomerReq {
@IsString()
company_name?: string
}