Skip to content

Commit

Permalink
feat: add area, color, etc....
Browse files Browse the repository at this point in the history
  • Loading branch information
jingming295 committed Jan 12, 2024
1 parent ae4bdbb commit c4d8a1b
Show file tree
Hide file tree
Showing 48 changed files with 4,044 additions and 442 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build
on:
push:
branches:
- master

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set Up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install Dependencies of frontend
run: npm install

- name: Install Typescript for frontend
run: npm install typescript --save-dev

- name: Run Build for frontend
run: npm run build

- name: Install Dependencies of backend
run: cd server && npm install

- name: Install Typescript for backend
run: cd server && npm install typescript --save-dev

- name: Run Start for backend
run: cd server && npm run start
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ dist/

# Avatar Folder
server/Avatars/*
!server/Avatars/1.png
!server/Avatars/1.png

# Test Folder
test/*
27 changes: 27 additions & 0 deletions server/src/SQL/dbInsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,32 @@ export class DBInsert extends DatabaseConnector
[]
);
}

async addColorScheme(textColor: string, backgroundColor: string): Promise<ResultSetHeader>{
return this.executeQuery(
`INSERT INTO tb_colorscheme (cs_textColor, cs_backgroundColor)
VALUES (?, ?);
`,
[textColor, backgroundColor]
);
}

async addBigArea(name: string): Promise<ResultSetHeader>{
return this.executeQuery(
`INSERT INTO tb_bigarea (ba_name)
VALUES (?);
`,
[name]
);
}

async addSubArea(name: string, bigAreaID: number, colorSchemeID: number): Promise<ResultSetHeader>{
return this.executeQuery(
`INSERT INTO tb_subarea (aa_area, bigarea, aa_colorscheme)
VALUES (?, ?, ?);
`,
[name, bigAreaID, colorSchemeID]
);
}

}
91 changes: 85 additions & 6 deletions server/src/SQL/dbSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,103 @@ export class DBSelect extends DatabaseConnector
);
}

async selectUserIDStatusByToken(token: string): Promise<{ u_id: number; u_active:number}[]>
async selectUserIDStatusByToken(token: string): Promise<{ u_id: number; u_active: number; }[]>
{
return await this.executeQuery<{ u_id: number; u_active:number}>(
return await this.executeQuery<{ u_id: number; u_active: number; }>(
`SELECT u_id, u_active FROM tb_user WHERE u_token = ?`,
[token]
);
}

async selectAllArticleArea(){
return await this.executeQuery<{ba_name:string; aa_area:string;}>(
`SELECT tb_bigarea.ba_name, tb_subarea.aa_area
async selectAllArticleArea()
{
return await this.executeQuery<{ ba_id: number, ba_name: string, aa_id: number, aa_area: string, cs_id: number, cs_textColor: string, cs_backgroundColor: string; }>(
`SELECT tb_bigarea.ba_id, tb_bigarea.ba_name, tb_subarea.aa_id, tb_subarea.aa_area, tb_subarea.aa_colorscheme,tb_colorscheme.cs_id, tb_colorscheme.cs_textColor, tb_colorscheme.cs_backgroundColor
FROM tb_bigarea
LEFT JOIN tb_subarea
ON tb_bigarea.ba_id = tb_subarea.bigarea AND tb_subarea.aa_alive = 1
LEFT JOIN tb_colorscheme
ON tb_subarea.aa_colorscheme = tb_colorscheme.cs_id
WHERE tb_bigarea.ba_alive = 1
ORDER BY tb_bigarea.ba_id, tb_subarea.aa_id;
ORDER BY tb_bigarea.ba_id, tb_subarea.aa_id;
`
);
}
async selectAllColorScheme()
{
return await this.executeQuery<{ cs_id: number; cs_textColor: string; cs_backgroundColor: string; }>(
`SELECT cs_id, cs_textColor, cs_backgroundColor FROM tb_colorscheme WHERE cs_alive = 1`
);
}

async checkColorSchemeConstraint(id: number)
{
return await this.executeQuery<{ aa_colorscheme: number; }>(
`SELECT tb_subarea.*, tb_colorscheme.*
FROM tb_subarea
LEFT JOIN tb_colorscheme ON tb_subarea.aa_colorscheme = tb_colorscheme.cs_id
WHERE tb_colorscheme.cs_id = ? AND tb_subarea.aa_alive = 1;
`,
[id]
);
}

async selectAllArticleBigArea()
{
return await this.executeQuery<{ ba_id: number; ba_name: string; }>(
`SELECT * FROM tb_bigarea WHERE ba_alive = 1`
);
}

async checkBigAreaConstraint(id: number)
{
return await this.executeQuery<{ aa_area: number; }>(
`SELECT tb_bigarea.ba_id
FROM tb_bigarea
JOIN tb_subarea ON tb_bigarea.ba_id = tb_subarea.bigarea
WHERE tb_subarea.aa_alive = 1 AND tb_bigarea.ba_id = ?;
`,
[id]
);
}

async selectBigAreaByID(id: number)
{
return await this.executeQuery<{ ba_id: number; ba_name: string; }>(
`SELECT * FROM tb_bigarea WHERE ba_id = ?`,
[id]
);
}

async selectSubAreaByID(id: number)
{
return await this.executeQuery<{ aa_id: number; aa_area: string; aa_colorscheme: number; }>(
`SELECT * FROM tb_subarea WHERE aa_id = ?`,
[id]
);
}

async selectColorSchemeByID(id: number)
{
return await this.executeQuery<{ cs_id: number; cs_textColor: string; cs_backgroundColor: string; }>(
`SELECT * FROM tb_colorscheme WHERE cs_id = ?`,
[id]
);
}

async checkSubAreaConstraint(id: number)
{
return await this.executeQuery<{ aa_area: number; }>(
`SELECT tb_subarea.aa_id
FROM tb_subarea
INNER JOIN tb_article
ON tb_subarea.aa_id = tb_article.article_area
WHERE tb_subarea.aa_id = ? AND tb_article.article_alive = 1;
`,
[id]
);
}

}
53 changes: 53 additions & 0 deletions server/src/SQL/dbUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,57 @@ export class DBUpdate extends DatabaseConnector
[id]
);
}

async deleteColorScheme(id:number): Promise<ResultSetHeader>
{
return this.executeQuery(
`UPDATE tb_colorscheme
SET cs_alive = 0
WHERE cs_id = ?;
`,
[id]
);
}

async deleteBigArea(id:number): Promise<ResultSetHeader>
{
return this.executeQuery(
`UPDATE tb_bigarea
SET ba_alive = 0
WHERE ba_id = ?;
`,
[id]
);
}
async updateBigArea(id:number, name:string): Promise<ResultSetHeader>
{
return this.executeQuery(
`UPDATE tb_bigarea
SET ba_name = ?
WHERE ba_id = ?;
`,
[name, id]
);
}

async updateSubAreaData(id:number, name:string, bigAreaID:number, colorSchemeID:number): Promise<ResultSetHeader>
{
return this.executeQuery(
`UPDATE tb_subarea
SET aa_area = ?, bigarea = ?, aa_colorscheme = ?
WHERE aa_id = ?;
`,
[name, bigAreaID, colorSchemeID, id]
);
}

async deleteSubArea(id:number): Promise<ResultSetHeader>{
return this.executeQuery(
`UPDATE tb_subarea
SET aa_alive = 0
WHERE aa_id = ?;
`,
[id]
);
}
}
30 changes: 24 additions & 6 deletions server/src/Validators/inputControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export class InputControl
}
validateUserDesc(userDesc: string): void
{
if (userDesc.length > 100)
if (userDesc.length < 1 || userDesc.length > 100)
{
throw new ValidationError(-400, 'Please input a correct user description, must be less than 100 characters.');
throw new ValidationError(-400, 'Please input a correct user description, must be less than 100 characters or more than 1 character and contain only alphanumeric characters and spaces.');
}
}

Expand All @@ -72,9 +72,9 @@ export class InputControl
{
const domainRegex = /^(?:(?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,61})?[a-zA-Z0-9]\.)+[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]$/;

if (domainname.length > 254)
if (domainname.length < 1 || domainname.length > 254)
{
throw new ValidationError(-400, 'Domain name is too long');
throw new ValidationError(-400, 'Domain name is too long or too short');
} else if (!domainRegex.test(domainname))
{
throw new ValidationError(-400, 'Domain name is invalid');
Expand All @@ -83,9 +83,9 @@ export class InputControl

validateSMTPPassword(password: string): void
{
if (password.length > 200)
if (password.length < 1 || password.length > 200)
{
throw new ValidationError(-400, 'SMTP password is too long');
throw new ValidationError(-400, 'SMTP password is too long or too short');
}
}

Expand Down Expand Up @@ -116,4 +116,22 @@ export class InputControl
}
}

validateBigAreaName(name: string): void
{
if (name.length < 1 || name.length > 20 || !/^[a-zA-Z0-9 ]*$/.test(name))
{
throw new ValidationError(-400, 'Please input a correct big area name, must be less than 20 characters and contain only alphanumeric characters and spaces.');
}
}

validateSubAreaName(name: string): void
{
if (name.length < 1 || name.length > 20 || !/^[a-zA-Z0-9 ]*$/.test(name))
{
throw new ValidationError(-400, 'Please input a correct sub area name, must be less than 20 characters and contain only alphanumeric characters and spaces.');
}
}



}
24 changes: 22 additions & 2 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ import updateEmailSettings from './routes/UpdateEmailSettings';
import sendTestEmail from './routes/SendTestEmail';
import activateAccountRequest from './routes/ActivateAccountRequest';
import getAllArticleArea from './routes/GetAllArticleArea';
import getAllColorScheme from './routes/GetAllColorScheme';
import deleteColorScheme from './routes/DeleteColorScheme';
import addColorScheme from './routes/AddColorScheme';
import getAllArticleBigArea from './routes/GetAllArticleBigArea';
import deleteBigArea from './routes/DeleteBigArea';
import updateBigArea from './routes/UpdateBigArea';
import addBigArea from './routes/AddBigArea';
import updateSubArea from './routes/UpdateSubArea';
import deleteSubArea from './routes/DeleteSubArea';
import addSubArea from './routes/AddSubArea';
import { Init } from './Init';

const app = express();
const port = 3000;

app.use(express.json());

app.use('/avatars', express.static('Avatars'))
app.use('/avatars', express.static('Avatars'));

app.use(cors());

Expand All @@ -52,7 +62,17 @@ const routers = [
updateEmailSettings,
sendTestEmail,
activateAccountRequest,
getAllArticleArea
getAllArticleArea,
getAllColorScheme,
deleteColorScheme,
addColorScheme,
getAllArticleBigArea,
deleteBigArea,
updateBigArea,
addBigArea,
updateSubArea,
deleteSubArea,
addSubArea
];
app.use('/', routers);

Expand Down
Loading

0 comments on commit c4d8a1b

Please sign in to comment.