Skip to content

Commit

Permalink
Merge pull request #80 from RnDAO/78-create-a-new-schema-for-roles-an…
Browse files Browse the repository at this point in the history
…d-channels

78-create-a-new-schema-for-roles-and-channels
  • Loading branch information
cyri113 authored Jun 26, 2023
2 parents 5221325 + 6b7bbb8 commit 49ed0fd
Show file tree
Hide file tree
Showing 45 changed files with 260 additions and 207 deletions.
15 changes: 12 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"es2021": true,
"node": true
},
"extends": ["standard-with-typescript", "prettier"],
"extends": [
"standard-with-typescript",
"prettier"
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -12,5 +15,11 @@
"project": "./tsconfig.json"
},
"rules": {},
"ignorePatterns": ["coverage", "dist"]
}
"ignorePatterns": [
"coverage",
"dist",
"__tests__/",
"jest.config.ts",
"*.yml"
]
}
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: CI Pipeline

on: pull_request
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Publish

on:
Expand Down
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
dist
coverage
node_modules
44 changes: 34 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ The CI Pipeline uses [super-linter](https://github.com/super-linter/super-linter
docker run -e RUN_LOCAL=true -e TYPESCRIPT_DEFAULT_STYLE=prettier -e VALIDATE_DOCKERFILE_HADOLINT=false -v $(pwd):/tmp/lint github/super-linter:slim-latest
```

```bash
Windows: docker run -e RUN_LOCAL=true -e TYPESCRIPT_DEFAULT_STYLE=prettier -e VALIDATE_DOCKERFILE_HADOLINT=false -v "$(Resolve-Path .):/tmp/lint" github/super-linter:slim-latest
```

Note: We have disabled HADOLINT for now as we are getting an error: `qemu: uncaught target signal 11 (Segmentation fault) - core dumped`.

[![Maintainability](https://api.codeclimate.com/v1/badges/52d516c2ad7c262adb37/maintainability)](https://codeclimate.com/github/RnDAO/tc-dbComm/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/52d516c2ad7c262adb37/test_coverage)](https://codeclimate.com/github/RnDAO/tc-dbComm/test_coverage)


### Tests

The CI Pipeline uses the `test` target from the Dockerfile to run the tests. You can run it locally with the following command:
Expand All @@ -27,9 +32,7 @@ docker compose -f docker-compose.test.yml up --exit-code-from app --build

Note: This will create a /coverage folder where you can review the coverage details.

## Schema

### rawinfo
### Schema for rawinfo

```ts
rawinfo {
Expand All @@ -49,7 +52,7 @@ rawinfo {
}
```

### user
### Schema for user

```ts
User {
Expand All @@ -71,7 +74,7 @@ User {
}
```

### heatmap
### Schema for heatmap

```ts
HeatMap {
Expand All @@ -92,7 +95,7 @@ HeatMap {
}
```

### guildMembers
### Schema for guildMembers

```ts
GuildMember {
Expand All @@ -107,7 +110,7 @@ GuildMember {

```

### memberactivities
### Schema for memberactivities

```ts
memberactivities {
Expand All @@ -131,7 +134,7 @@ memberactivities {
}
```

### channels
### Schema for channels

```ts
Channels {
Expand All @@ -141,7 +144,7 @@ Channels {
}
```

### token
### Schema for token

```ts
Token {
Expand All @@ -153,7 +156,7 @@ Token {
}
```

### guild
### Schema for guild

```ts
Guild {
Expand All @@ -175,3 +178,24 @@ Guild {
window: Array<number>
}
```

### Schema for channel

```ts
Channel {
id: Snowflake,
name?: string | null,
parent_id?: string | null,
}
```


### Schema for role

```ts
Role {
id: Snowflake,
name: string,
color: number,
}
```
18 changes: 18 additions & 0 deletions __tests__/unit/models/channel.model.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Channel } from '../../../src/models';
import { IChannel } from '../../../src/interfaces';

describe('Channel model', () => {
describe('channel validation', () => {
let channel: IChannel;
beforeEach(() => {
channel = {
id: '123',
name: 'channel1',
parent_id: 'admin',
};
});
test('should correctly validate a valid Channel data', async () => {
await expect(new Channel(channel).validate()).resolves.toBeUndefined();
});
});
});
4 changes: 2 additions & 2 deletions __tests__/unit/models/guild.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Guild } from '../../../src/models';
import { IGuild } from '../../../src/interfaces/Guild.interface';
import { IGuild } from '../../../src/interfaces';
import moment from 'moment';

describe('Guild model', () => {
Expand All @@ -22,7 +22,7 @@ describe('Guild model', () => {
isInProgress: false,
icon: null,
window: [7, 1],
action: [1, 1, 1, 4, 3, 5, 5, 4, 3, 3, 2, 2, 1],
action: [1, 1, 1, 4, 3, 5, 5, 4, 3, 3, 2],
};
});

Expand Down
6 changes: 3 additions & 3 deletions __tests__/unit/models/guildMember.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GuildMember } from '../../../src/models';
import { IGuildMember } from '../../../src/interfaces/GuildMember.interface';
import { IGuildMember } from '../../../src/interfaces';
import moment from 'moment';

describe('Account model', () => {
describe('account validation', () => {
describe('guildMember model', () => {
describe('guildMember validation', () => {
let guildMember: IGuildMember;
beforeEach(() => {
guildMember = {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/models/heatMap.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HeatMap } from '../../../src/models';
import { IHeatMap } from '../../../src/interfaces/HeatMap.interface';
import { IHeatMap } from '../../../src/interfaces';

describe('HeatMap model', () => {
describe('heatMap validation', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/models/memberActivity.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MemberActivity } from '../../../src/models';
import { IMemberActivity } from '../../../src/interfaces/MemberActivity.interface';
import { IMemberActivity } from '../../../src/interfaces';

describe('MemberActivity model', () => {
describe('MemberActivity validation', () => {
Expand Down
18 changes: 18 additions & 0 deletions __tests__/unit/models/role.model.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Role } from '../../../src/models';
import { IRole } from '../../../src/interfaces';

describe('Role model', () => {
describe('role validation', () => {
let role: IRole;
beforeEach(() => {
role = {
id: '123',
name: 'role1',
color: 1234,
};
});
test('should correctly validate a valid Role data', async () => {
await expect(new Role(role).validate()).resolves.toBeUndefined();
});
});
});
2 changes: 1 addition & 1 deletion __tests__/unit/models/token.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Token } from '../../../src/models';
import { IToken } from '../../../src/interfaces/Token.interface';
import { IToken } from '../../../src/interfaces';
import moment from 'moment';

describe('Token model', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/models/user.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { User } from '../../../src/models';
import { IUser } from '../../../src/interfaces/User.interface';
import { IUser } from '../../../src/interfaces';

describe('User model', () => {
describe('User validation', () => {
Expand Down
1 change: 1 addition & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: '3.9'

services:
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@togethercrew.dev/db",
"version": "2.3.2",
"version": "2.4.0",
"description": "All interactions with DB",
"main": "./dist/index.js",
"scripts": {
"build": "tsc",
"start": "node ./dist/index.js",
"dev": "nodemon ./src/magic.ts",
"dev": "nodemon ./src/index.ts",
"test": "jest --detectOpenHandles",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"format": "prettier --write \"src/**/*.ts\" \"__tests__/unit/models/**/*.ts\" ",
"prepublishOnly": "npm test",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
Expand Down Expand Up @@ -54,4 +54,4 @@
"files": [
"dist/**/*"
]
}
}
69 changes: 4 additions & 65 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,4 @@
import { User, Token, Guild, HeatMap, RawInfo, MemberActivity } from './models';
import {
guildMemberSchema,
guildSchema,
heatMapSchema,
MemberActivitySchema,
rawInfoSchema,
tokenSchema,
userSchema,
} from './models/schemas';
import {
IDiscordGuild,
IDiscordOathBotCallback,
IDiscordUser,
IDiscordGuildMember,
IDiscordChannel,
} from './interfaces/Discord.interface';
import { IUser, IUserUpdateBody, UserModel } from './interfaces/User.interface';
import { IToken, ITokenUpdateBody, TokenModel } from './interfaces/Token.interface';
import { IGuild, IGuildUpdateBody, GuildModel } from './interfaces/Guild.interface';
import { IGuildMember, IGuildMemberUpdateBody, GuildMemberModel } from './interfaces/GuildMember.interface';
import { IRawInfo, IRawInfoUpdateBody, RawInfoModel } from './interfaces/RawInfo.interface';

import { IMemberActivity, MemberActivityModel } from './interfaces/MemberActivity.interface';
import { databaseService, heatmapService } from './service';

export {
User,
Token,
Guild,
HeatMap,
RawInfo,
MemberActivity,
IDiscordGuild,
IDiscordOathBotCallback,
IDiscordUser,
IDiscordGuildMember,
IDiscordChannel,
IUser,
IRawInfo,
IRawInfoUpdateBody,
IUserUpdateBody,
IMemberActivity,
MemberActivityModel,
UserModel,
IToken,
ITokenUpdateBody,
TokenModel,
IGuild,
IGuildUpdateBody,
GuildModel,
IGuildMember,
IGuildMemberUpdateBody,
GuildMemberModel,
RawInfoModel,
databaseService,
heatmapService,
guildMemberSchema,
guildSchema,
heatMapSchema,
MemberActivitySchema,
rawInfoSchema,
tokenSchema,
userSchema,
};
export * from './models';
export * from './models/schemas';
export * from './interfaces';
export * from './service';
Loading

0 comments on commit 49ed0fd

Please sign in to comment.