Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion amplify/data/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const schema = a
lastFourDigits: a.integer(),
})
.identifier(['id'])
.secondaryIndexes(index => [index('userId')])
.authorization(allow => [
allow.ownerDefinedIn('userId').to(['read', 'update', 'delete']),
allow.authenticated().to(['create']),
Expand Down Expand Up @@ -114,7 +115,8 @@ const schema = a
onboardingCompleted: a.boolean().required(),
onboardingData: a.json(),
})
.secondaryIndexes(index => [index('userId')])
.identifier(['storeId'])
.secondaryIndexes(index => [index('userId'), index('customDomain'), index('storeName')])
.authorization(allow => [allow.authenticated().to(['read', 'update', 'delete', 'create'])]),

Product: a
Expand Down
10 changes: 5 additions & 5 deletions amplify/functions/LambdaEncryptKeys/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ export const handler = async (event: any) => {
}

// Si hay storeId, cifrar y guardar en la tienda
const { data: stores } = await client.models.UserStore.list({
filter: { storeId: { eq: storeId } },
const { data: stores } = await client.models.UserStore.get({
storeId: storeId,
})

if (!stores || stores.length === 0) {
if (!stores) {
return {
statusCode: 404,
body: JSON.stringify({ success: false, message: 'Tienda no encontrada' }),
Expand All @@ -120,7 +120,7 @@ export const handler = async (event: any) => {
}
}

const store = stores[0]
const store = stores

// Cifrar la API Key
const encryptedKey = encrypt(apiKey)
Expand Down Expand Up @@ -205,7 +205,7 @@ export const handler = async (event: any) => {

// Actualizar la tienda
await client.models.UserStore.update({
id: store.id,
storeId: store.storeId,
...updateData,
})

Expand Down
6 changes: 2 additions & 4 deletions amplify/functions/checkStoreDomain/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ export const handler = async (event: any) => {
}

try {
const { data: stores } = await clientSchema.models.UserStore.list({
filter: {
customDomain: { eq: domainName },
},
const { data: stores } = await clientSchema.models.UserStore.listUserStoreByCustomDomain({
customDomain: domainName,
})

return {
Expand Down
6 changes: 2 additions & 4 deletions amplify/functions/checkStoreName/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ export const handler = async (event: any) => {
}

try {
const { data: stores } = await clientSchema.models.UserStore.list({
filter: {
storeName: { eq: storeName },
},
const { data: stores } = await clientSchema.models.UserStore.listUserStoreByStoreName({
storeName: storeName,
})

return {
Expand Down
15 changes: 9 additions & 6 deletions amplify/functions/getStoreCollections/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getAmplifyDataClientConfig } from '@aws-amplify/backend/function/runtim
import { env } from '$amplify/env/getStoreCollections'
import { type Schema } from '../../data/resource'

// Lazy-load del cliente para evitar reconfiguración en cada invocación
let clientSchema: ReturnType<typeof generateClient<Schema>> | null = null

const initializeClient = async () => {
Expand Down Expand Up @@ -53,12 +52,16 @@ export const handler = async (event: any) => {
}

// Obtener productos asociados a esta colección
const { data: products } = await client.models.Product.list({
filter: {
collectionId: { eq: collectionId },
status: { eq: 'active' },
const { data: products } = await client.models.Product.listProductByCollectionId(
{
collectionId: collectionId,
},
})
{
filter: {
status: { eq: 'active' },
},
}
)

return {
statusCode: 200,
Expand Down
13 changes: 4 additions & 9 deletions amplify/functions/getStoreData/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getAmplifyDataClientConfig } from '@aws-amplify/backend/function/runtim
import { env } from '$amplify/env/getStoreData'
import { type Schema } from '../../data/resource'

// Lazy-load del cliente para evitar reconfiguración en cada invocación
let clientSchema: ReturnType<typeof generateClient<Schema>> | null = null

const initializeClient = async () => {
Expand All @@ -16,9 +15,9 @@ const initializeClient = async () => {
return clientSchema
}
export const handler = async (event: any) => {
const storeId = event.queryStringParameters?.storeId
const storeName = event.queryStringParameters?.storeName

if (!storeId) {
if (!storeName) {
return {
statusCode: 400,
body: JSON.stringify({ message: 'Store ID is required' }),
Expand All @@ -31,12 +30,8 @@ export const handler = async (event: any) => {

try {
const client = await initializeClient()
const { data: store } = await client.models.UserStore.list({
filter: {
storeId: {
eq: storeId,
},
},
const { data: store } = await client.models.UserStore.listUserStoreByStoreName({
storeName: storeName,
})

if (!store) {
Expand Down
14 changes: 9 additions & 5 deletions amplify/functions/getStoreProducts/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ export const handler = async (event: any) => {

try {
const client = await initializeClient()
const { data: products } = await client.models.Product.list({
filter: {
storeId: { eq: storeId },
status: { eq: 'active' }, // Opcional: filtrar solo productos activos
const { data: products } = await client.models.Product.listProductByStoreId(
{
storeId: storeId,
},
})
{
filter: {
status: { eq: 'active' }, // Opcional: filtrar solo productos activos
},
}
)

return {
statusCode: 200,
Expand Down
Loading
Loading