Skip to content
Open
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
83 changes: 83 additions & 0 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
rules: {
curly: ['error', 'all'],
eqeqeq: ['error', 'smart'],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
optionalDependencies: false,
peerDependencies: false,
},
],
'no-shadow': [
'error',
{
hoist: 'all',
},
],
'prefer-const': 'error',
'import/order': [
'error',
{
groups: [
['external', 'builtin'],
'internal',
['parent', 'sibling', 'index'],
],
},
],
'sort-imports': [
'error',
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
},
],
'padding-line-between-statements': [
'error',
{
blankLine: 'always',
prev: '*',
next: 'return',
},
],
},
root: true,
plugins: ['import'],
env: {
node: true,
es6: true,
},
overrides: [
{
files: ['**/*.ts?(x)'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
rules: {
'@typescript-eslint/prefer-optional-chain': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/strict-boolean-expressions': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'prettier/prettier': 'error',
'@typescript-eslint/no-var-requires': 'off',
},
},
],
};
18 changes: 0 additions & 18 deletions backend/.eslintrc.json

This file was deleted.

15 changes: 8 additions & 7 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
"devDependencies": {
"@types/aws-lambda": "8.10.17",
"@types/node": "10.12.18",
"@types/serverless": "^1.72.4",
"@types/serverless": "^1.78.36",
"@types/uuid": "3.4.5",
"@typescript-eslint/eslint-plugin": "2.0.0",
"@typescript-eslint/parser": "2.0.0",
"eslint": "6.2.2",
"eslint-config-prettier": "6.1.0",
"eslint-plugin-prettier": "3.1.0",
"prettier": "1.18.2",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.4.1",
"serverless": "^1.83.0",
"serverless-step-functions": "^2.21.1",
"serverless-webpack": "5.2.0",
Expand Down
47 changes: 37 additions & 10 deletions backend/serverless.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import * as AwsConfig from 'serverless/aws';

import ApiGatewayErrors from './resources/apiGatewayErrors';
import dynamodb from './resources/dynamodb';

const serverlessConfiguration: AwsConfig.Serverless = {
service: 'dojo-serverless-backend',
Expand All @@ -15,16 +17,16 @@ const serverlessConfiguration: AwsConfig.Serverless = {
stage: 'dev',
profile: 'dojo-serverless',
iamRoleStatements: [
// {
// Effect: 'Allow',
// Action: [
// 'dynamodb:Query',
// 'dynamodb:PutItem',
// 'dynamodb:DeleteItem',
// 'dynamodb:ListStreams',
// ],
// Resource: { 'Fn::GetAtt': ['DojoServerlessTable', 'Arn'] },
// },
{
Effect: 'Allow',
Action: [
'dynamodb:Query',
'dynamodb:PutItem',
'dynamodb:DeleteItem',
'dynamodb:ListStreams',
],
Resource: { 'Fn::GetAtt': ['DojoServerlessTable', 'Arn'] },
},
],
usagePlan: {
quota: {
Expand Down Expand Up @@ -63,10 +65,35 @@ const serverlessConfiguration: AwsConfig.Serverless = {
},
],
},
createVirus: {
handler: 'src/handlers/virus/create.main',
events: [
{
http: {
method: 'post',
path: 'virus',
cors: true,
},
},
],
},
deleteVirus: {
handler: 'src/handlers/virus/delete.main',
events: [
{
http: {
method: 'delete',
path: 'virus/{virusId}',
cors: true,
},
},
],
},
},
resources: {
Resources: {
...ApiGatewayErrors,
DojoServerlessTable: dynamodb,
},
},
};
Expand Down
25 changes: 25 additions & 0 deletions backend/src/handlers/virus/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { failure, success } from '@libs/response';
import { APIGatewayProxyHandler } from 'aws-lambda';
import { DynamoDB } from 'aws-sdk';
import uuid from 'uuid';

const documentClient = new DynamoDB.DocumentClient();

export const main: APIGatewayProxyHandler = async () => {
const virusId = uuid();
try {
await documentClient
.put({
TableName: 'dojo-serverless-table',
Item: {
partitionKey: 'Virus',
sortKey: virusId,
},
})
.promise();

return success({ id: virusId });
} catch (e) {
return failure({ e });
}
};
27 changes: 27 additions & 0 deletions backend/src/handlers/virus/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { failure, success } from '@libs/response';
import { APIGatewayProxyHandler } from 'aws-lambda';
import { DynamoDB } from 'aws-sdk';

const documentClient = new DynamoDB.DocumentClient();

export const main: APIGatewayProxyHandler = async ({ pathParameters }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux typer pathParameters

if (pathParameters == null) {
return failure({});
}
const virusId = pathParameters.virusId;
try {
await documentClient
.delete({
TableName: 'dojo-serverless-table',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux mettre ça dans une constante

Key: {
partitionKey: 'Virus',
sortKey: virusId,
},
})
.promise();

return success({});
} catch (e) {
return failure({ e });
}
};
30 changes: 21 additions & 9 deletions backend/src/handlers/virus/get.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { failure, success } from '@libs/response';
import { Item } from '@libs/types';
import { APIGatewayProxyHandler } from 'aws-lambda';
import uuid from 'uuid';
import { DynamoDB } from 'aws-sdk';

import { success } from '@libs/response';
const documentClient = new DynamoDB.DocumentClient();
interface Virus extends Item {
partitionKey: 'Virus';
}

export const main: APIGatewayProxyHandler = async () => {
const viruses = [
{ id: uuid() },
{ id: uuid() },
{ id: uuid() },
{ id: uuid() },
];
try {
const { Items = [] } = await documentClient
.query({
TableName: 'dojo-serverless-table',
KeyConditionExpression: 'partitionKey = :partitionKey',
ExpressionAttributeValues: { ':partitionKey': 'Virus' },
})
.promise();

return success({ viruses });
return success({
loadedViruses: (Items as Virus[]).map(({ sortKey }) => ({ id: sortKey })),
});
} catch (e) {
return failure({ e });
}
};
Loading