Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend changes #14

Merged
merged 12 commits into from
Jul 29, 2022
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
Binary file added .DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions .vtexignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.DS_Store
.git
node_modules/
node/node_modules/
node/tslint.json
react/node_modules/
.vscode/
.gitignore

node/**/__tests__/**
node/**/__mocks__/**
node/**/__snapshots__/**
node/**/*.test.js
node/**/*.test.ts
node/**/*.test.tsx
2 changes: 1 addition & 1 deletion BackEnd-AWS/dreamscape-authorizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports.handler = async function(event, context, callback) {
const { headers } = normalizeEvent(event);


const authorization = headers.Authorization ?? headers.authorization
const authorization = headers['Proxy-Authorization'] ?? headers['Proxy-Authorization']
if (authorization) {
const responseGetUserVtex = await axios.get( `https://${process.env.account}.myvtex.com/api/vtexid/pub/authenticated/user?authToken=${authorization}`,{ // CHECK IF IS A VTEX AUTHENTICATED USER
headers: {
Expand Down
8 changes: 4 additions & 4 deletions BackEnd-AWS/dreamscape-suggestionsDelete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ exports.handler = async event => {
const params = {
TableName: table,
"Key": {
"email": pathParameters['email'],
"productId": pathParameters['productId']
"month": pathParameters['month'],
"orderId": pathParameters['orderId']
}
};

try {
const dyn = await dynamo.delete(params, () => {}).promise();
return response(200, `Record ${pathParameters['productId']} has been deleted`);
await dynamo.delete(params, () => {}).promise();
return response(200, `Record ${pathParameters['orderId']} has been deleted`);
} catch (err) {
console.error(err);
return response(500, 'Somenthing went wrong');
Expand Down
14 changes: 7 additions & 7 deletions BackEnd-AWS/dreamscape-suggestionsGet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ exports.handler = async event => {

try {
let data = {};
if (pathParameters && pathParameters['email']) { // verify if has email
if(pathParameters['productId']) { // verify if has productId
if (pathParameters && pathParameters['month']) { // verify if has date
if(pathParameters['orderId']) { // verify if has month
data = await dynamo
.get({
...params,
Key: {// get data that has the email requested and productId
email: pathParameters['email'],
productId: pathParameters['productId']
Key: {// get data that has the date requested and month
month: pathParameters['month'],
orderId: pathParameters['orderId'],
},

})
Expand All @@ -35,9 +35,9 @@ exports.handler = async event => {
data = await dynamo
.query({
ExpressionAttributeValues: {
':e': pathParameters['email'], // get data that has the email requested
':e': pathParameters['month'], // get data that has the date requested
},
KeyConditionExpression: 'email = :e',
KeyConditionExpression: 'month = :e',
TableName: table,
})
.promise();
Expand Down
19 changes: 5 additions & 14 deletions BackEnd-AWS/dreamscape-suggestionsPost/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,14 @@ exports.handler = async event => {
const params = {
TableName: table,
Item: {
email: data.email,
productId: data.productId
month: data.month,
orderId: data.orderId,
date: data.date,
products: data.products
},
};
await dynamo.put(params).promise();
let newSuggestion = {};
newSuggestion = await dynamo
.get({
TableName: table,
Key: {
email: params.Item.email,
productId: params.Item.productId
},

})
.promise();
return response(200, newSuggestion);
return response(200, `Record ${data.orderId} saved with success`);
} catch (err) {
console.error(err);
return response(500, 'Somenthing went wrong');
Expand Down
14 changes: 8 additions & 6 deletions BackEnd-AWS/dreamscape-suggestionsPut/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ exports.handler = async event => {
throw new Error('No table name defined.');
}

const { pathParameters } = normalizeEvent(event);
const { data,pathParameters } = normalizeEvent(event);

if(!pathParameters || !pathParameters['email'] || !pathParameters['productId']){
if(!pathParameters || !pathParameters['month'] || !pathParameters['orderId']){
throw new Error('Invalid Request.');
}
const params = {
TableName: table,
Key: {
email: pathParameters['email'],
productId: pathParameters['productId']
month: pathParameters['month'],
orderId: pathParameters['orderId']
},
UpdateExpression: 'set #a = :d',
UpdateExpression: 'set #a = :d, #f = :h',
ExpressionAttributeNames: {
'#a': 'updated_at',
'#f': 'products'
},
ExpressionAttributeValues: {
':d': new Date().toISOString()
':d': new Date().toISOString(),
':h': data.products
},
};

Expand Down
4 changes: 4 additions & 0 deletions BackEnd-Vtex/graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type Query {
testHelloWorldResolver: String
}

21 changes: 18 additions & 3 deletions BackEnd-Vtex/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"categories": [],
"dependencies": {},
"builders": {
"node": "6.x"
"node": "6.x",
"graphql": "1.x"
},
"scripts": {
"prereleasy": "bash lint.sh"
Expand All @@ -27,6 +28,13 @@
"path": "/api/oms/pvt/orders/*"
}
},
{
"name": "outbound-access",
"attrs": {
"host": "portal.vtexcommercestable.com.br",
"path": "/api/oms/pvt/orders/*"
}
},
{
"name": "outbound-access",
"attrs": {
Expand Down Expand Up @@ -56,11 +64,18 @@
"path": "/api/profile-system/*"
}
},
{
"name": "outbound-access",
"attrs": {
"host": "2zxs9i4im3.execute-api.us-east-1.amazonaws.com",
"path": "/v1/*"
}
},
{
"name": "outbound-access",
"attrs": {
"host": "2zxs9i4im3.execute-api.us-east-1.amazonaws.com",
"path": "/v1/*"
"host": "grhrvkk2k9.execute-api.us-east-1.amazonaws.com",
"path": "/default/*"
}
},
{
Expand Down
15 changes: 15 additions & 0 deletions BackEnd-Vtex/node/.vtexignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.DS_Store
.git
node_modules/
node/node_modules/
node/tslint.json
react/node_modules/
.vscode/
.gitignore

node/**/__tests__/**
node/**/__mocks__/**
node/**/__snapshots__/**
node/**/*.test.js
node/**/*.test.ts
node/**/*.test.tsx
4 changes: 4 additions & 0 deletions BackEnd-Vtex/node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IOClients } from "@vtex/api";
import { OMS } from "@vtex/clients";
import Suggestion from "./suggestion";
import { Profile } from "./profile";
import TestHelloWorld from "./testHelloWorld";

// Extend the default IOClients implementation with our own custom clients.
export class Clients extends IOClients {
Expand All @@ -14,4 +15,7 @@ export class Clients extends IOClients {
public get profile() {
return this.getOrSet('profile', Profile)
}
public get testHelloWorld() {
return this.getOrSet('profile', TestHelloWorld)
}
}
5 changes: 2 additions & 3 deletions BackEnd-Vtex/node/clients/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ export default class Suggestion extends ExternalClient {
super('https://2zxs9i4im3.execute-api.us-east-1.amazonaws.com/v1/suggestion', context, {
...options,
headers: {
...(options && options.headers),
Authorization: context.authToken
...(options && options.headers)
},
retries: 0
retries: 0,
})
}

Expand Down
19 changes: 19 additions & 0 deletions BackEnd-Vtex/node/clients/testHelloWorld.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ExternalClient, InstanceOptions, IOContext } from '@vtex/api'
export default class TestHelloWorld extends ExternalClient {
constructor(context: IOContext, options?: InstanceOptions) {
super('https://grhrvkk2k9.execute-api.us-east-1.amazonaws.com', context, {
...options,
headers: {
...(options && options.headers)
},
retries: 0,
})
}

public go = () => {

return this.http.get(`default/myFunctionName`)

}

}
31 changes: 22 additions & 9 deletions BackEnd-Vtex/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import type { ClientsConfig, ServiceContext, EventContext } from '@vtex/api'
import { method, Service } from '@vtex/api'

import { Clients } from './clients'
import { suggestion } from './middlewares/suggestion'
import { suggestionByMonth } from './middlewares/suggestionByMonth'
import { suggestionAll } from './middlewares/suggestionAll'
import { suggestionPut } from './middlewares/suggestionPut'
import { suggestionPost } from './middlewares/suggestionPost'
import { someStates } from './middlewares/someStates'
//import { someStates } from './middlewares/someStates'
import { testHelloWorldResolver } from './resolvers/testHelloWorld'


const TIMEOUT_MS = 800

Expand All @@ -23,8 +25,9 @@ const clients: ClientsConfig<Clients> = {
declare global {
type Context = ServiceContext<Clients>
interface SuggestionData {
email: string
points: number
month: string
orderId: string
products: Record<string,any>[]

}
interface StatusChangeContext extends EventContext<Clients> {
Expand All @@ -38,23 +41,33 @@ declare global {
}
}
}
export default new Service({


//export default new Service<Clients, State, ParamsContext>({
export default new Service({
graphql: {
resolvers: {
Query: {
testHelloWorldResolver,
},
},
},
clients,
routes: {
suggestionOne: method({
GET: [suggestion],
suggestionByMonth: method({
GET: [suggestionByMonth],
}),
suggestionAll: method({
GET: [suggestionAll],
}),
suggestionPut: method({
PATCH: [suggestionPut],
PUT: [suggestionPut],
}),
suggestionPost: method({
POST: [suggestionPost],
}),
},
events: {
someStates,
//someStates,
},
})
Loading