Skip to content

Commit

Permalink
fix codeforjapan#114 lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Hal Seki authored and Hal Seki committed Mar 12, 2021
1 parent fb2a4a2 commit 885c0bd
Show file tree
Hide file tree
Showing 22 changed files with 24,677 additions and 659 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/plugins/*
src/webpack/*
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@ module.exports = {
'prettier/@typescript-eslint',
],
rules: {
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-explicit-any":"off",
"@typescript-eslint/no-unsafe-return":"off",
"@typescript-eslint/prefer-regexp-exec": "warn",
"@typescript-eslint/no-namespace":"off"
},
};
23,911 changes: 23,877 additions & 34 deletions package-lock.json

Large diffs are not rendered by default.

52 changes: 29 additions & 23 deletions src/aws/centerTable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
import { v4 as uuid } from 'uuid'
import { AWSError, DynamoDB } from 'aws-sdk'
import {Center, CenterParam} from '../lambda/definitions/types'
import { v4 as uuid } from "uuid";
import { AWSError, DynamoDB } from "aws-sdk";
import { Center, CenterParam } from "../lambda/definitions/types";
export default class CenterTable {
client: DynamoDB.DocumentClient;
constructor(serviceClient: DynamoDB.DocumentClient) {
Expand All @@ -10,7 +10,7 @@ export default class CenterTable {

getCenters() {
const params: DynamoDB.ScanInput = {
TableName: process.env.CENTER_TABLE_NAME!
TableName: process.env.CENTER_TABLE_NAME!,
};
return new Promise((resolve, reject) => {
this.client.scan(params, (err, data) => {
Expand All @@ -29,8 +29,8 @@ export default class CenterTable {
const params: DynamoDB.DocumentClient.GetItemInput = {
TableName: process.env.CENTER_TABLE_NAME!,
Key: {
"centerId": centerId
}
centerId: centerId,
},
};
return new Promise((resolve, reject) => {
this.client.get(params, (err, data) => {
Expand All @@ -39,7 +39,7 @@ export default class CenterTable {
reject(err);
} else {
console.log("getCenter Success!");
console.log(data.Item!)
console.log(data.Item!);
resolve(data.Item! as Center);
}
});
Expand Down Expand Up @@ -76,24 +76,30 @@ export default class CenterTable {
...body,
centerId: centerId,
};
const exp = Object.keys(body).reduce((previous:string, current: string) => {
if (previous === "") {
return `${current} = :${current}`
}else{
previous = previous + `, ${current} = :${current}`
return previous
}
}, "")
const expvalues = Object.keys(body).reduce((previous: any, current: string) => {
previous[`:${current}`] = (body[current] as string)
return previous
}, {})
console.log(exp)
console.log(expvalues)
const exp = Object.keys(body).reduce(
(previous: string, current: string) => {
if (previous === "") {
return `${current} = :${current}`;
} else {
previous = previous + `, ${current} = :${current}`;
return previous;
}
},
""
);
const expvalues = Object.keys(body).reduce(
(previous: any, current: string) => {
previous[`:${current}`] = body[current] as string;
return previous;
},
{}
);
console.log(exp);
console.log(expvalues);
const params: DynamoDB.DocumentClient.UpdateItemInput = {
TableName: process.env.CENTER_TABLE_NAME!,
Key: {
centerId: center.centerId
centerId: center.centerId,
},
UpdateExpression: "set " + exp,
ExpressionAttributeValues: expvalues,
Expand All @@ -112,4 +118,4 @@ export default class CenterTable {
});
});
}
};
}
125 changes: 70 additions & 55 deletions src/aws/cognito_admin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
"use strict";

import { APIGatewayProxyEvent } from 'aws-lambda';
import AWS, { CognitoIdentityServiceProvider } from 'aws-sdk';
import { APIGatewayProxyEvent } from "aws-lambda";
import AWS, { CognitoIdentityServiceProvider } from "aws-sdk";

export interface Config {
userPoolId: string;
Expand All @@ -14,47 +14,57 @@ export interface Config {
// import configFile from '../config/dev.json';

AWS.config.update({
region: 'ap-northeast-1',
region: "ap-northeast-1",
});


export class CognitoAdmin {
cognito: CognitoIdentityServiceProvider
user: CognitoIdentityServiceProvider.AdminInitiateAuthResponse | undefined
config: Config
cognito: CognitoIdentityServiceProvider;
user: CognitoIdentityServiceProvider.AdminInitiateAuthResponse | undefined;
config: Config;
constructor(config: Config) {
this.cognito = new AWS.CognitoIdentityServiceProvider({
apiVersion: '2016-04-18'
apiVersion: "2016-04-18",
});
this.config = config;
this.user = undefined;
}
/**
* Signup
* Signup
* @param username user name
*/
async signUp(username: string, password?: string): Promise<{ username: string, password: string, user: CognitoIdentityServiceProvider.AdminSetUserPasswordResponse }> {
async signUp(
username: string,
password?: string
): Promise<{
username: string;
password: string;
user: CognitoIdentityServiceProvider.AdminSetUserPasswordResponse;
}> {
const userPoolId = this.config.userPoolId;
// サインイン
const user = await this.cognito.adminCreateUser({
UserPoolId: userPoolId,
Username: username,
}).promise();
console.log('登録完了', JSON.stringify(user, null, 4));
const user = await this.cognito
.adminCreateUser({
UserPoolId: userPoolId,
Username: username,
})
.promise();
console.log("登録完了", JSON.stringify(user, null, 4));
// if password is not specified, create random password
if (password == undefined) {
password = this.makePassword();
}
// 作成したばかりのユーザーはステータス FORCE_CHANGE_PASSWORD なのでパスワード変更
// べつに一時パスワードと同じパスワードでもエラーにはならない
await this.cognito.adminSetUserPassword({
UserPoolId: userPoolId,
Username: username,
Password: password,
Permanent: true
}).promise();
console.log('パスワード変更完了');
return { username: username, password: password, user: user }
await this.cognito
.adminSetUserPassword({
UserPoolId: userPoolId,
Username: username,
Password: password,
Permanent: true,
})
.promise();
console.log("パスワード変更完了");
return { username: username, password: password, user: user };
}
/**
* サインイン
Expand All @@ -65,59 +75,64 @@ export class CognitoAdmin {
const userPoolId = this.config.userPoolId;
const clientId = this.config.userPoolClientId;
// サインイン
this.user = await this.cognito.adminInitiateAuth({
UserPoolId: userPoolId,
ClientId: clientId,
AuthFlow: 'ADMIN_NO_SRP_AUTH',
AuthParameters: {
USERNAME: username,
PASSWORD: password
}
}).promise();
console.log('サインイン完了', JSON.stringify(this.user, null, 4));
this.user = await this.cognito
.adminInitiateAuth({
UserPoolId: userPoolId,
ClientId: clientId,
AuthFlow: "ADMIN_NO_SRP_AUTH",
AuthParameters: {
USERNAME: username,
PASSWORD: password,
},
})
.promise();
console.log("サインイン完了", JSON.stringify(this.user, null, 4));
return this.user;
}
/**
/**
* refreshToken でログインし直し
* @param refreshToken refresh token
*/
async refreshToken(refreshToken: string) {
const userPoolId = this.config.userPoolId;
const clientId = this.config.userPoolClientId;
// サインイン
this.user = await this.cognito.adminInitiateAuth({
UserPoolId: userPoolId,
ClientId: clientId,
AuthFlow: 'REFRESH_TOKEN_AUTH',
AuthParameters: {
REFRESH_TOKEN: refreshToken
}
}).promise();
console.log('サインイン完了', JSON.stringify(this.user, null, 4));
this.user = await this.cognito
.adminInitiateAuth({
UserPoolId: userPoolId,
ClientId: clientId,
AuthFlow: "REFRESH_TOKEN_AUTH",
AuthParameters: {
REFRESH_TOKEN: refreshToken,
},
})
.promise();
console.log("サインイン完了", JSON.stringify(this.user, null, 4));
return this.user;
}
// パスワードを生成する
makePassword() {
let pwd = Math.random().toString(36).substr(2, 8)
let pwd = Math.random().toString(36).substr(2, 8);
let count = 0;
// 数字とアルファベット両方入っているかチェックする
while ((pwd.match(/[a-zA-Z]/) && pwd.match(/\d/)) == null) {
if (count > 100) break
pwd = Math.random().toString(36).substr(2, 8)
if (count > 100) break;
pwd = Math.random().toString(36).substr(2, 8);
count = count + 1;
}
return pwd
return pwd;
}
/**
* return UserID from Authorization header striing
* @param authHeader Authorization: header
*/
getUserId(event: APIGatewayProxyEvent) {
if (!event.headers['Authorization']) return null;
const authHeader = event.headers['Authorization']
const payload = Buffer.from(authHeader.split(".")[1], 'base64').toString('ascii')
console.log(payload)
return JSON.parse(payload)['cognito:username']
if (!event.headers["Authorization"]) return null;
const authHeader = event.headers["Authorization"];
const payload = Buffer.from(authHeader.split(".")[1], "base64").toString(
"ascii"
);
console.log(payload);
return JSON.parse(payload)["cognito:username"];
}

}
}
33 changes: 20 additions & 13 deletions src/aws/nurseTable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
import { AWSError, DynamoDB } from 'aws-sdk'
import { NurseParam } from '../lambda/definitions/types'
import { Center } from '../lambda/definitions/types'
import { AWSError, DynamoDB } from "aws-sdk";
import { NurseParam } from "../lambda/definitions/types";
import { Center } from "../lambda/definitions/types";

export default class NurseTable {
client: DynamoDB.DocumentClient;
Expand All @@ -10,7 +10,7 @@ export default class NurseTable {
}
getNurses(centerId: string) {
const params: DynamoDB.ScanInput = {
TableName: process.env.NURSE_TABLE_NAME!
TableName: process.env.NURSE_TABLE_NAME!,
};
return new Promise((resolve, reject) => {
this.client.scan(params, (err, data) => {
Expand All @@ -19,29 +19,36 @@ export default class NurseTable {
reject(err);
} else {
console.log("getNurse Success!");
const filtered = data.Items!.filter(item => item.manageCenters.findIndex((center: Center) => center.centerId === centerId) > -1);
const filtered = data.Items!.filter(
(item) =>
item.manageCenters.findIndex(
(center: Center) => center.centerId === centerId
) > -1
);
resolve({ Count: filtered.length, Items: filtered });
}
});
});
}

getNurse(nurseId: string): Promise<DynamoDB.DocumentClient.GetItemOutput | AWSError> {
getNurse(
nurseId: string
): Promise<DynamoDB.DocumentClient.GetItemOutput | AWSError> {
const params: DynamoDB.DocumentClient.GetItemInput = {
TableName: process.env.NURSE_TABLE_NAME!,
Key: {
"nurseId": nurseId
}
nurseId: nurseId,
},
};
console.log(params)
console.log(params);
return new Promise((resolve, reject) => {
this.client.get(params, (err, data) => {
if (err) {
console.log(err);
reject(err);
} else {
console.log("getNurse Success!");
console.log(data.Item)
console.log(data.Item);
resolve(data.Item!);
}
});
Expand Down Expand Up @@ -72,11 +79,11 @@ export default class NurseTable {
const params: DynamoDB.DocumentClient.UpdateItemInput = {
TableName: process.env.NURSE_TABLE_NAME!,
Key: {
nurseId: nurseId
nurseId: nurseId,
},
UpdateExpression: "set manageCenters = :c",
ExpressionAttributeValues: {
":c": body.manageCenters
":c": body.manageCenters,
},
};
console.log(params);
Expand All @@ -93,4 +100,4 @@ export default class NurseTable {
});
});
}
};
}
Loading

0 comments on commit 885c0bd

Please sign in to comment.