Allow the API to create customers
This commit is contained in:
36
lib/bigcommerce/api/customers/handlers/create-customer.ts
Normal file
36
lib/bigcommerce/api/customers/handlers/create-customer.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { CustomersHandlers } from '..'
|
||||
|
||||
const createCustomer: CustomersHandlers['createCustomer'] = async ({
|
||||
res,
|
||||
body: { firstName, lastName, email, password },
|
||||
config,
|
||||
}) => {
|
||||
// TODO: Add proper validations with something like Ajv
|
||||
if (!(firstName && lastName && email && password)) {
|
||||
return res.status(400).json({
|
||||
data: null,
|
||||
errors: [{ message: 'Invalid request' }],
|
||||
})
|
||||
}
|
||||
// TODO: validate the password.
|
||||
// Passwords must be at least 7 characters and contain both alphabetic
|
||||
// and numeric characters.
|
||||
|
||||
const { data } = await config.storeApiFetch('/v3/customers', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify([
|
||||
{
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
email,
|
||||
authentication: {
|
||||
new_password: password,
|
||||
},
|
||||
},
|
||||
]),
|
||||
})
|
||||
|
||||
res.status(200).json({ data })
|
||||
}
|
||||
|
||||
export default createCustomer
|
||||
Reference in New Issue
Block a user