Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Feat: Role/ProjectMember #30

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5f5fd3e
chore: build
buqiyuan Nov 21, 2022
cc8d913
chore: update config
buqiyuan Nov 21, 2022
0b1642c
fix: update add project logic
buqiyuan Dec 14, 2022
2106900
chore: merge code
buqiyuan Dec 15, 2022
6f74c9c
feat: add some entity
buqiyuan Dec 23, 2022
9087399
chore: submit code to review
buqiyuan Dec 23, 2022
f99b58d
feat: add project member permission
scarqin Dec 23, 2022
88ab5f7
chore: submit code to scar review
buqiyuan Dec 23, 2022
f0b1f3b
chore: submit code to scar review
buqiyuan Dec 23, 2022
1f78e3a
chore: publish
buqiyuan Dec 23, 2022
dfadabc
refactor: rename roleName to role
buqiyuan Dec 23, 2022
0a7025c
add userID
buqiyuan Dec 23, 2022
89bf28b
chore: update code
buqiyuan Dec 23, 2022
4f7a921
feat: sort memberlist
buqiyuan Dec 23, 2022
23fe9d8
fix: project editor without add member
scarqin Dec 23, 2022
da04337
feat: sort memberlist
buqiyuan Dec 23, 2022
163fe7a
fix: request body type
buqiyuan Dec 23, 2022
86516e7
fix: request body type
buqiyuan Dec 23, 2022
07ceefe
fix: request body type
buqiyuan Dec 23, 2022
613a264
fix: request body type
buqiyuan Dec 23, 2022
8e316d7
fix: request body type
buqiyuan Dec 23, 2022
301c0b8
fix: remove default logic
buqiyuan Dec 23, 2022
c31ea58
chore: update .env
buqiyuan Dec 26, 2022
fbd4c10
chore: update .env
buqiyuan Dec 26, 2022
9e5daca
Merge branch 'dev' of https://github.com/eolinker/eoapi-remote-server…
scarqin Dec 26, 2022
3a674bb
feat: projectExport parse to tree
scarqin Dec 27, 2022
861237f
feat: errors to error
scarqin Dec 27, 2022
971952f
feat: add workspace cancel auto create project
scarqin Dec 28, 2022
b1077ae
docs: update README
scarqin Dec 30, 2022
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
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MYSQL_HOST=localhost
MYSQL_PORT=33066
MYSQL_PORT=3306
1 change: 1 addition & 0 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
id: docker_build
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64
push: true
tags: eolinker/eoapi-remote-server:dev
- name: Image digest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-latest.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build Latest Image

on:
release:
types:
- "published"
push:
tags:
- 'v*.*.*'

env:
VERSION: ${{ github.ref_name }}
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
此仓库已归档

# eoapi-remote-server

Eoapi 远程数据源后端服务,部署后即可通过公共数据源实现简单团队协作。

如果你的数据不需要共享,也可以仅下载客户端单机使用
如果你的数据不需要共享,也可以仅下载 Eoapi 客户端单机使用

## 部署
请访问 [部署文档](https://docs.eoapi.io/docs/storage.html)

请访问 [部署文档](https://github.com/eolinker/eoapi-remote-server/wiki/%E4%BA%91%E7%AB%AF%E6%9C%8D%E5%8A%A1)

## 开发

Node.js 版本:^16

如果想提高开发效率,可以安装 NestJS 官方提供的命令行 nestjs/cli 快速生成组件、服务等模板。
Expand All @@ -24,10 +29,11 @@ docker-compose run -d --service-ports mysql
1. 安装依赖

```bash
yarn
yarn
```

2. 运行数据库迁移脚本

```bash
yarn migration:run
```
Expand All @@ -40,8 +46,8 @@ yarn start:dev

### 运行

| 命令 | 描述 |
| --------------- | ---------- |
| 命令 | 描述 |
| ------------------- | ---------- |
| `npm run start:dev` | 运行服务器 |

### 更新数据库
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
eoapi-remote-server:
# build: 从当前路径构建镜像
# build: .
image: eolinker/eoapi-remote-server:latest
image: eolinker/eoapi-remote-server:dev
container_name: eoapi-remote-server
deploy:
restart_policy:
Expand Down Expand Up @@ -35,7 +35,7 @@ services:
- eoapi_net

eoapi:
image: eolinker/eoapi:latest
image: eolinker/eoapi:dev
container_name: eoapi
deploy:
restart_policy:
Expand All @@ -51,7 +51,7 @@ services:
- eoapi_net

eoapi-test-server:
image: eolinker/eoapi-test-server:latest
image: eolinker/eoapi-test-server:dev
container_name: eoapi-test-server
deploy:
restart_policy:
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eoapi-remote-server",
"version": "1.11.0",
"version": "2.0.0",
"description": "Storage api data in remote server",
"author": "eoapi",
"private": true,
Expand All @@ -13,9 +13,10 @@
"start:dev": "rimraf dist && cross-env NODE_ENV=development nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "cross-env NODE_ENV=production node dist/src/main.js",
"createDatabase": "node ./scripts/auto-create-database.js",
"migration:create": "npx typeorm-ts-node-commonjs migration:create ./src/migrations/create-table",
"migration:generate": "node ./scripts/migration-generate.js",
"migration:run": "npm run build&&npx typeorm-ts-node-commonjs migration:run -d ./src/config/data-source.ts",
"migration:run": "npm run createDatabase && npm run build&&npx typeorm-ts-node-commonjs migration:run -d ./src/config/data-source.ts",
"migration:revert": "npx typeorm-ts-node-commonjs migration:revert -d ./src/config/data-source.ts",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"typeorm": "npx typeorm-ts-node-commonjs",
Expand Down Expand Up @@ -46,6 +47,8 @@
"class-validator": "^0.13.2",
"cross-env": "^7.0.3",
"crypto-js": "^4.1.1",
"dayjs": "^1.11.7",
"lodash": "^4.17.21",
"mysql2": "^2.3.3",
"nanoid": "^3.3.4",
"passport": "^0.6.0",
Expand All @@ -64,6 +67,7 @@
"@types/crypto-js": "^4.1.1",
"@types/express": "^4.17.14",
"@types/jest": "29.2.2",
"@types/lodash": "^4.14.191",
"@types/node": "^18.11.9",
"@types/passport": "^1.0.11",
"@types/passport-http": "^0.3.9",
Expand Down
27 changes: 27 additions & 0 deletions scripts/auto-create-database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const mysql = require('mysql2');
const dotenv = require('dotenv');
dotenv.config();

const con = mysql.createConnection({
host: process.env.MYSQL_HOST,
port: Number.parseInt(process.env.MYSQL_PORT, 10),
user: process.env.MYSQL_USERNAME,
password: process.env.MYSQL_PASSWORD || process.env.MYSQL_ROOT_PASSWORD,
});

con.connect((err) => {
if (err) throw err;
console.log('Connected!');

const sql = `CREATE DATABASE if not EXISTS ${process.env.MYSQL_DATABASE} CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci`;

con.query(sql, (err) => {
if (err) {
console.log(err.sqlMessage);
} else {
console.log('Database created');
}

process.exit();
});
});
13 changes: 11 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { APP_GUARD } from '@nestjs/core';
import { AppController } from './app.controller';
import { AppService } from './app.service';
// 引入数据库的及配置文件
Expand All @@ -10,6 +11,7 @@ import { getConfiguration } from './config/configuration';
import { UserModule } from '@/modules/user/user.module';
import { WorkspaceModule } from '@/modules/workspace/workspace.module';
import { SharedModule } from '@/shared/shared.module';
import { JwtAuthGuard } from '@/guards';

console.log('process.env.NODE_ENV', `.env.${process.env.NODE_ENV}`);
@Module({
Expand All @@ -33,14 +35,21 @@ console.log('process.env.NODE_ENV', `.env.${process.env.NODE_ENV}`);
logging: configService.get('database.logging'),
timezone: configService.get('database.timezone'), // 时区
}),
}), // 数据库
}),
// 数据库
WorkspaceModule,
SharedModule,
AuthModule, // 认证
UserModule,
ShareDocsModule,
],
controllers: [AppController],
providers: [AppService],
providers: [
AppService,
{
provide: APP_GUARD,
useClass: JwtAuthGuard,
},
],
})
export class AppModule {}
6 changes: 6 additions & 0 deletions src/common/decorators/permission.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { SetMetadata } from '@nestjs/common';
import { PermissionEnum } from '@/enums/permission.enum';

export const PERMISSIONS_KEY = 'permissions';
export const Permissions = (permissions: PermissionEnum) =>
SetMetadata(PERMISSIONS_KEY, permissions);
1 change: 1 addition & 0 deletions src/config/data-source.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'reflect-metadata';
import * as dotenv from 'dotenv';
import { DataSource } from 'typeorm';

import { getConfiguration } from './configuration';
dotenv.config();

Expand Down
70 changes: 70 additions & 0 deletions src/entities/base.new.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { ApiHideProperty, ApiProperty } from '@nestjs/swagger';
import {
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
DeleteDateColumn,
Generated,
} from 'typeorm';
import { Exclude, Transform } from 'class-transformer';
import dayjs from 'dayjs';

export class BaseTimestampEntity {
@ApiProperty({ type: Date, description: '创建时间' })
@Transform(({ value }) => dayjs(value).format('YYYY-MM-DD HH:mm:ss'), {
toPlainOnly: true,
})
@CreateDateColumn({
type: 'datetime',
nullable: false,
name: 'created_at',
comment: '创建时间',
})
createdAt: Date | null;

@ApiProperty({ type: Date, description: '更新时间' })
@UpdateDateColumn({
type: 'datetime',
name: 'updated_at',
comment: '更新时间',
})
@Transform(({ value }) => dayjs(value).format('YYYY-MM-DD HH:mm:ss'), {
toPlainOnly: true,
})
updatedAt: Date | null;

@Exclude()
@DeleteDateColumn({
type: 'datetime',
name: 'deleted_at',
select: false,
comment: '删除时间',
})
@Transform(({ value }) => dayjs(value).format('YYYY-MM-DD HH:mm:ss'), {
toPlainOnly: true,
})
deletedAt: Date;
}

export class BaseGeneratedEntity extends BaseTimestampEntity {
@ApiHideProperty()
@Exclude()
@PrimaryGeneratedColumn({ name: 'id', comment: '主键ID' })
id: number;

@ApiProperty({ type: String, description: 'uuid' })
@Column({ comment: '业务 UUID' })
@Generated('uuid')
uuid: string;
}

export class BaseEntity extends BaseGeneratedEntity {
@ApiProperty({ type: Number, description: '创建者' })
@Column('bigint', { name: 'create_by', nullable: true, comment: '创建者' })
createBy: number | null;

@ApiProperty({ type: Number, description: '更新者' })
@Column('bigint', { name: 'update_by', nullable: true, comment: '更新者' })
updateBy: number | null;
}
19 changes: 19 additions & 0 deletions src/entities/permission.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.new.entity';

@Entity({ name: 'permission' })
export class PermissionEntity extends BaseEntity {
@ApiProperty({ type: String, description: '权限名称' })
@Column({ type: 'varchar', unique: true, length: 120, comment: '权限名称' })
name: string;

@ApiProperty({ type: Number, description: '权限状态' })
@Column({
type: 'tinyint',
width: 1,
default: 1,
comment: '状态:0=禁用 1=启用',
})
status: number;
}
22 changes: 22 additions & 0 deletions src/entities/project-user-role.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.new.entity';

@Entity({ name: 'project_user_role' })
export class ProjectUserRoleEntity extends BaseEntity {
@Column({
name: 'project_id',
type: 'int',
comment: '项目ID',
})
projectID: number;

@Column({
name: 'user_id',
type: 'int',
comment: '用户ID',
})
userID: number;

@Column({ name: 'role_id', type: 'int', comment: '角色ID' })
roleID: number;
}
15 changes: 15 additions & 0 deletions src/entities/role-permission.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.new.entity';

@Entity({ name: 'role_permission' })
export class RolePermissionEntity extends BaseEntity {
@Column({ type: 'int', name: 'role_id', unsigned: true, comment: '角色ID' })
roleID: number;

@Column({
type: 'int',
name: 'permission_id',
comment: '权限ID',
})
permissionID: number;
}
23 changes: 23 additions & 0 deletions src/entities/role.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.new.entity';

@Entity({ name: 'role' })
export class RoleEntity extends BaseEntity {
@Column({
type: 'varchar',
length: 50,
comment: '角色名称',
})
name: string;

@Column({
type: 'tinyint',
width: 1,
unsigned: true,
comment: '角色类别: 1=空间 2=项目',
})
module: number;

@Column({ type: 'varchar', length: 200, default: '', comment: '角色备注' })
remark: string;
}
22 changes: 22 additions & 0 deletions src/entities/workspace-user-role.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.new.entity';

@Entity({ name: 'workspace_user_role' })
export class WorkspaceUserRoleEntity extends BaseEntity {
@Column({
name: 'workspace_id',
type: 'int',
comment: '空间ID',
})
workspaceID: number;

@Column({
name: 'user_id',
type: 'int',
comment: '用户ID',
})
userID: number;

@Column({ name: 'role_id', type: 'int', comment: '角色ID' })
roleID: number;
}
Loading