-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [add] - セッション情報を取得するSocketハンドラと関数作成 * [add] - セッションデータをログアウト(削除)させる関数とSocketハンドラ作成 * [fix] - オフセットの位置調整がおかしかった * [add] - セッション名を変更するSocketハンドラと関数作成
- Loading branch information
Showing
4 changed files
with
207 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import sqlite3 from "sqlite3"; | ||
const db = new sqlite3.Database("./records/USER.db"); | ||
|
||
/** | ||
* セッション名を変更 | ||
* @param _userId | ||
* @param _targetSessionId | ||
* @param _newName | ||
* @returns | ||
*/ | ||
export default async function changeSessionName( | ||
_userId: string, | ||
_targetSessionId: string, | ||
_newName: string | ||
):Promise<boolean> { | ||
try { | ||
|
||
return new Promise((resolve) => { | ||
db.run( | ||
` | ||
UPDATE USERS_SESSION SET sessionName=? | ||
WHERE userId=? AND sessionId=? | ||
`, | ||
[_newName, _userId, _targetSessionId], | ||
(err:Error) => { | ||
//エラーハンドラ | ||
if (err) { | ||
console.log("changeSessionname :: db(セッション名変更) : エラー->", err); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
); | ||
}); | ||
|
||
} catch(e) { | ||
|
||
console.log("changeSessionname: エラー->", e); | ||
return false; | ||
|
||
} | ||
} |
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,43 @@ | ||
import sqlite3 from "sqlite3"; | ||
const db = new sqlite3.Database("./records/USER.db"); | ||
|
||
import type { IUserSession } from "../../type/User"; | ||
|
||
/** | ||
* 指定したユーザーのセッションデータを取得 | ||
* @param _userId | ||
* @param _indexNumber | ||
* @returns | ||
*/ | ||
export default async function fetchSession(_userId: string, _indexNumber: number) | ||
:Promise<IUserSession[] | null> { | ||
try { | ||
|
||
//オフセットでずらすデータ数 | ||
const offsetNum = 10 * (_indexNumber-1 || 0); | ||
|
||
return new Promise((resolve) => { | ||
db.all( | ||
"SELECT * FROM USERS_SESSION WHERE userId=? LIMIT 10 OFFSET ?", | ||
[_userId, offsetNum], | ||
(err:Error, sessionData:IUserSession[]) => { | ||
//エラーハンドラ | ||
if (err) { | ||
resolve(null); | ||
return; | ||
} | ||
|
||
//データを返す | ||
resolve(sessionData); | ||
return; | ||
} | ||
); | ||
}); | ||
|
||
} catch(e) { | ||
|
||
console.log("fetchSession :: エラー->", e); | ||
return null; | ||
|
||
} | ||
} |
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,34 @@ | ||
import sqlite3 from "sqlite3"; | ||
const db = new sqlite3.Database("./records/USER.db"); | ||
|
||
/** | ||
* セッションをログアウトさせる | ||
*/ | ||
export default async function sessionLogout(_userId:string, _targetSessionId:string):Promise<boolean> { | ||
try { | ||
|
||
return new Promise((resolve) => { | ||
db.run( | ||
"DELETE FROM USERS_SESSION WHERE userId=? AND sessionId=?", | ||
[_userId, _targetSessionId], | ||
(err:Error) => { | ||
//エラーハンドラ | ||
if (err) { | ||
console.log("sessionLogout :: db(削除) : エラー->", err); | ||
resolve(false); | ||
return; | ||
} | ||
|
||
resolve(true); | ||
return; | ||
} | ||
) | ||
}) | ||
|
||
} catch(e) { | ||
|
||
console.log("sessionLogout :: エラー->", e); | ||
return false; | ||
|
||
} | ||
} |
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