-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Refactor and migrate Personalization to
app
router INTER-911…
…, INTER-459 (#165) * chore: move personalization client to app * chore: move personalization api to app part 1 * chore: move personalization api to app part 2 * chore: move personalization api to app part 3 * fix search terms query * fix products query * rough refactor done * move files to `app` * move files to `app`, remove deprecated code * chore: self review fixes * chore: self review fixes
- Loading branch information
Showing
63 changed files
with
552 additions
and
1,113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/server/coupon-fraud/database.ts → src/app/coupon-fraud/api/claim/database.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/server/credentialStuffing/database.ts → ...ial-stuffing/api/authenticate/database.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ProductDbModel, UserCartItemAttributes, UserCartItemDbModel } from '../../database'; | ||
import { Op } from 'sequelize'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { getAndValidateFingerprintResult, Severity } from '../../../../../server/checks'; | ||
|
||
export type AddCartItemPayload = { | ||
requestId: string; | ||
productId: number; | ||
}; | ||
|
||
export type AddCartItemResponse = { | ||
severity: Severity; | ||
message: string; | ||
data?: UserCartItemAttributes; | ||
}; | ||
|
||
export async function POST(req: NextRequest): Promise<NextResponse<AddCartItemResponse>> { | ||
const { requestId, productId } = (await req.json()) as AddCartItemPayload; | ||
|
||
// Get the full Identification result from Fingerprint Server API and validate its authenticity | ||
const fingerprintResult = await getAndValidateFingerprintResult({ | ||
requestId, | ||
req, | ||
options: { minConfidenceScore: 0.3, disableFreshnessCheck: true }, | ||
}); | ||
if (!fingerprintResult.okay) { | ||
return NextResponse.json({ severity: 'error', message: fingerprintResult.error }, { status: 403 }); | ||
} | ||
|
||
// Get visitorId from the Server API Identification event | ||
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId; | ||
if (!visitorId) { | ||
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 }); | ||
} | ||
|
||
const product = await ProductDbModel.findOne({ | ||
where: { | ||
id: { | ||
[Op.eq]: productId, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!product) { | ||
return NextResponse.json({ severity: 'error', message: 'Product not found' }, { status: 500 }); | ||
} | ||
|
||
const [cartItem, created] = await UserCartItemDbModel.findOrCreate({ | ||
where: { | ||
visitorId: { | ||
[Op.eq]: visitorId ?? '', | ||
}, | ||
productId: { | ||
[Op.eq]: productId, | ||
}, | ||
}, | ||
defaults: { | ||
visitorId: visitorId ?? '', | ||
count: 1, | ||
timestamp: new Date(), | ||
productId, | ||
}, | ||
}); | ||
|
||
if (!created) { | ||
cartItem.count++; | ||
await cartItem.save(); | ||
} | ||
|
||
return NextResponse.json({ | ||
severity: 'success', | ||
message: 'Item added', | ||
data: cartItem, | ||
}); | ||
} |
Oops, something went wrong.