Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "simple-import-sort", "prettier"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"simple-import-sort/imports": "error",
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"printWidth": 120,
"printWidth": 80,
"singleQuote": true,
"semi": true,
"useTabs": true
Expand Down
15 changes: 13 additions & 2 deletions db/migrations/20240409163927_create_users_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ export async function up(knex: Knex): Promise<void> {
table.string('password').notNullable();
table.string('bio');
table.string('avatarUrl');
table.enum('status', ['online', 'offline', 'away']).defaultTo('offline');
table.timestamps(true, true, true);
table
.enum('status', ['online', 'offline', 'away'])
.defaultTo('offline');
table
.dateTime('createdAt')
.notNullable()
.defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table
.dateTime('updatedAt')
.notNullable()
.defaultTo(
knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
);
});
}

Expand Down
13 changes: 12 additions & 1 deletion db/migrations/20240412000348_add_workspace_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ export async function up(knex: Knex): Promise<void> {
table.string('avatarUrl');
table.integer('ownerId').unsigned();
table.foreign('ownerId').references('id').inTable('users');
table.timestamps(true, true, true);

table
.dateTime('createdAt')
.notNullable()
.defaultTo(knex.raw('CURRENT_TIMESTAMP'));

table
.dateTime('updatedAt')
.notNullable()
.defaultTo(
knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
);
});
}

Expand Down
12 changes: 10 additions & 2 deletions db/migrations/20240412002911_add_channel_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ export async function up(knex: Knex): Promise<void> {
table.integer('creatorId').unsigned();
table.integer('workspaceId').unsigned();

//TODO: add this to another migrationFile
table.foreign('creatorId').references('id').inTable('users');
table.foreign('workspaceId').references('id').inTable('workspaces');
table.timestamps(true, true, true);
table
.dateTime('createdAt')
.notNullable()
.defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table
.dateTime('updatedAt')
.notNullable()
.defaultTo(
knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
);
});
}

Expand Down
12 changes: 10 additions & 2 deletions db/migrations/20240412002952_add_messages_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ export async function up(knex: Knex): Promise<void> {
table.foreign('senderId').references('id').inTable('users');
table.foreign('channelId').references('id').inTable('channels');
table.foreign('parentMessageId').references('id').inTable('messages');

table.timestamps(true, true, true);
table
.dateTime('createdAt')
.notNullable()
.defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table
.dateTime('updatedAt')
.notNullable()
.defaultTo(
knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
);
});
}

Expand Down
15 changes: 13 additions & 2 deletions db/migrations/20240412003023_add_invites_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ export async function up(knex: Knex): Promise<void> {
table.integer('senderId').unsigned();
table.integer('inviteeId').unsigned();

table.timestamps(true, true, true);
table.timestamp('expiresAt').notNullable();
table.enum('status', ['pending', 'accepted', 'cancelled']).defaultTo('pending');
table
.enum('status', ['pending', 'accepted', 'cancelled'])
.defaultTo('pending');

// TODO: add this to another migrationFile
table.foreign('workspaceId').references('id').inTable('workspaces');
table.foreign('inviteeId').references('id').inTable('users');
table.foreign('senderId').references('id').inTable('users');
table
.dateTime('createdAt')
.notNullable()
.defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table
.dateTime('updatedAt')
.notNullable()
.defaultTo(
knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
);
});
}

Expand Down
2 changes: 1 addition & 1 deletion db/migrations/20240412003051_add_notification_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { Knex } from 'knex';
notifications.message_id < messages.id
*/

//TODO: fix related repo and stuff.
//TODO: fix related repo and stuff, also add URL.
export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable('notifications', (table) => {
table.increments('id').primary();
Expand Down
48 changes: 42 additions & 6 deletions db/seeds/01-userSeeding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,47 @@ export async function seed(knex: Knex): Promise<void> {

// Inserts seed entries
await Promise.all([
EntityFactory.createUser(1, 'user 1', 'email1@gmail.com', 'Test User 1', 'password'),
EntityFactory.createUser(2, 'user 2', 'email2@gmail.com', 'Test User 2', 'password'),
EntityFactory.createUser(3, 'user 3', 'email3@gmail.com', 'Test User 3', 'password'),
EntityFactory.createUser(4, 'user 4', 'email4@gmail.com', 'Test User 4', 'password'),
EntityFactory.createUser(5, 'user 5', 'email5@gmail.com', 'Test User 5', 'password'),
EntityFactory.createUser(6, 'user 6', 'email6@gmail.com', 'Test User 6', 'password'),
EntityFactory.createUser(
1,
'user 1',
'email1@gmail.com',
'Test User 1',
'password'
),
EntityFactory.createUser(
2,
'user 2',
'email2@gmail.com',
'Test User 2',
'password'
),
EntityFactory.createUser(
3,
'user 3',
'email3@gmail.com',
'Test User 3',
'password'
),
EntityFactory.createUser(
4,
'user 4',
'email4@gmail.com',
'Test User 4',
'password'
),
EntityFactory.createUser(
5,
'user 5',
'email5@gmail.com',
'Test User 5',
'password'
),
EntityFactory.createUser(
6,
'user 6',
'email6@gmail.com',
'Test User 6',
'password'
),
]);
}
40 changes: 35 additions & 5 deletions db/seeds/02-workspaceSeeding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,40 @@ export async function seed(knex: Knex): Promise<void> {
* */

await Promise.all([
EntityFactory.createWorkspace(1, 1, 'workspace 1', 'Descrcription', 'url'),
EntityFactory.createWorkspace(2, 1, 'workspace 2', 'Descrcription', 'url'),
EntityFactory.createWorkspace(3, 6, 'workspace 3', 'Descrcription', 'url'),
EntityFactory.createWorkspace(4, 2, 'workspace 4', 'Descrcription', 'url'),
EntityFactory.createWorkspace(5, 5, 'workspace 5', 'Descrcription', 'url'),
EntityFactory.createWorkspace(
1,
1,
'workspace 1',
'Descrcription',
'url'
),
EntityFactory.createWorkspace(
2,
1,
'workspace 2',
'Descrcription',
'url'
),
EntityFactory.createWorkspace(
3,
6,
'workspace 3',
'Descrcription',
'url'
),
EntityFactory.createWorkspace(
4,
2,
'workspace 4',
'Descrcription',
'url'
),
EntityFactory.createWorkspace(
5,
5,
'workspace 5',
'Descrcription',
'url'
),
]);
}
63 changes: 56 additions & 7 deletions db/seeds/03-channelSeeding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,61 @@ export async function seed(knex: Knex): Promise<void> {
* */

await Promise.all([
EntityFactory.createChannel(1, 1, 1, 'channel 1', 'Descrcription', 'public'),
EntityFactory.createChannel(2, 1, 1, 'channel 2', 'Descrcription', 'public'),
EntityFactory.createChannel(3, 1, 2, 'channel 3', 'Descrcription', 'public'),
EntityFactory.createChannel(4, 2, 3, 'channel 4', 'Descrcription', 'public'),
EntityFactory.createChannel(5, 3, 4, 'channel 5', 'Descrcription', 'public'),
EntityFactory.createChannel(6, 3, 4, 'channel 6', 'Descrcription', 'public'),
EntityFactory.createChannel(7, 5, 5, 'channel 7', 'Descrcription', 'public'),
EntityFactory.createChannel(
1,
1,
1,
'channel 1',
'Descrcription',
'public'
),
EntityFactory.createChannel(
2,
1,
1,
'channel 2',
'Descrcription',
'public'
),
EntityFactory.createChannel(
3,
1,
2,
'channel 3',
'Descrcription',
'public'
),
EntityFactory.createChannel(
4,
2,
3,
'channel 4',
'Descrcription',
'public'
),
EntityFactory.createChannel(
5,
3,
4,
'channel 5',
'Descrcription',
'public'
),
EntityFactory.createChannel(
6,
3,
4,
'channel 6',
'Descrcription',
'public'
),
EntityFactory.createChannel(
7,
5,
5,
'channel 7',
'Descrcription',
'public'
),
]);
}
40 changes: 20 additions & 20 deletions db/seeds/06-messageSeeding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export async function seed(knex: Knex): Promise<void> {
* */

// workspace 1 channel 1(1,2,3,4)
EntityFactory.createMessage(1, 1, 1, 1, null, ''),
EntityFactory.createMessage(2, 2, 1, 1, null, ''),
EntityFactory.createMessage(3, 3, 1, 1, null, ''),
EntityFactory.createMessage(4, 4, 1, 1, 1, ''),
EntityFactory.createMessage(5, 1, 1, 1, 1, ''),
EntityFactory.createMessage(6, 3, 1, 1, 1, ''),
EntityFactory.createMessage(1, 1, 1, null, ''),
EntityFactory.createMessage(2, 2, 1, null, ''),
EntityFactory.createMessage(3, 3, 1, null, ''),
EntityFactory.createMessage(4, 4, 1, 1, ''),
EntityFactory.createMessage(5, 1, 1, 1, ''),
EntityFactory.createMessage(6, 3, 1, 1, ''),

/*
* 7[1]:
Expand All @@ -34,11 +34,11 @@ export async function seed(knex: Knex): Promise<void> {
* */

// workspace 1 channel 2(1,2)
EntityFactory.createMessage(7, 1, 2, 1, null, ''),
EntityFactory.createMessage(8, 4, 2, 1, null, ''),
EntityFactory.createMessage(9, 1, 2, 1, null, ''),
EntityFactory.createMessage(10, 4, 2, 1, null, ''),
EntityFactory.createMessage(11, 4, 2, 1, 7, ''),
EntityFactory.createMessage(7, 1, 2, null, ''),
EntityFactory.createMessage(8, 4, 2, null, ''),
EntityFactory.createMessage(9, 1, 2, null, ''),
EntityFactory.createMessage(10, 4, 2, null, ''),
EntityFactory.createMessage(11, 4, 2, 7, ''),

/*
* 12[1]:
Expand All @@ -47,9 +47,9 @@ export async function seed(knex: Knex): Promise<void> {
* */

// workspace 2 channel 3(1,5)
EntityFactory.createMessage(12, 1, 3, 2, null, ''),
EntityFactory.createMessage(13, 5, 3, 2, 12, ''),
EntityFactory.createMessage(14, 1, 3, 2, 12, ''),
EntityFactory.createMessage(12, 1, 3, null, ''),
EntityFactory.createMessage(13, 5, 3, 12, ''),
EntityFactory.createMessage(14, 1, 3, 12, ''),

/*
* 15[2]:
Expand All @@ -58,24 +58,24 @@ export async function seed(knex: Knex): Promise<void> {
* */

// workspace 3 channel 4(2,6)
EntityFactory.createMessage(15, 2, 4, 3, null, ''),
EntityFactory.createMessage(16, 6, 4, 3, null, ''),
EntityFactory.createMessage(17, 2, 4, 3, null, ''),
EntityFactory.createMessage(15, 2, 4, null, ''),
EntityFactory.createMessage(16, 6, 4, null, ''),
EntityFactory.createMessage(17, 2, 4, null, ''),

/*
* 18[2]:
* 19[3]:
* */

// workspace 4 channel 5(2,3)
EntityFactory.createMessage(18, 2, 5, 4, null, ''),
EntityFactory.createMessage(19, 3, 5, 4, null, ''),
EntityFactory.createMessage(18, 2, 5, null, ''),
EntityFactory.createMessage(19, 3, 5, null, ''),

/*
* 20[3]:
* */

// workspace 4 channel 6(3)
EntityFactory.createMessage(20, 3, 6, 4, 19, '4'),
EntityFactory.createMessage(20, 3, 6, 19, '4'),
]);
}
Loading