Skip to content

Commit

Permalink
Add activity-log comment. #41
Browse files Browse the repository at this point in the history
  • Loading branch information
haimkastner committed Apr 3, 2019
1 parent dd0e257 commit 95dddeb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/controllers/user-statuses-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getSpecificUserStatuses,
updateUserStatus
} from '../data';
import { Platform, UserStatusMap, Cache, Status } from '../core';
import { Platform, UserStatusMap, Cache, SetUserStatus } from '../core';
import { UserStatus, Pagination } from '../models';

const usersCache = new Cache(
Expand Down Expand Up @@ -128,9 +128,10 @@ export class UserStatusesController extends Controller {
@Put('statuses/{id}')
public async updateUser(
id: number,
@Body() { status }: { status: Status },

This comment has been minimized.

Copy link
@haimkastner

haimkastner Apr 3, 2019

Author Contributor

Apparently, if not using interface object type, the TSOA generate broken swagger.yaml file.

@Body() setUserStatus: SetUserStatus,
@Request() request: express.Request
): Promise<UserStatus> {
return await updateUserStatus(id, status, request.user);
const { status, comment } = setUserStatus;
return await updateUserStatus(id, status, request.user, comment);
}
}
5 changes: 5 additions & 0 deletions src/core/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ export interface SignedInfo {
adminId: number;
scope: Scope;
}

export interface SetUserStatus {
status: Status;
comment?: string;
}
3 changes: 2 additions & 1 deletion src/data/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const createNewReport = async (report: UserStatus, reporterKey: string) =

await saveActivity({
userStatusId: userStatus.id,
newStatus: status
newStatus: status,
comment: userStatus.description
});
};
6 changes: 4 additions & 2 deletions src/data/user-statuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export const getSpecificUserStatuses = async (
export const updateUserStatus = async (
id: number,
status: Status,
adminId: number
adminId: number,
comment: string
): Promise<UserStatus> => {
const botRepository = getConnection().getRepository(UserStatus);
const userStatus = await botRepository.findOne(id);
Expand All @@ -114,7 +115,8 @@ export const updateUserStatus = async (
userStatusId: userStatus.id,
oldStatus: userStatus.status,
newStatus: status,
adminId
adminId,
comment
});

return userStatus;
Expand Down
23 changes: 23 additions & 0 deletions src/migrations/1554323679399-add-activity-comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner, Table, TableColumn } from 'typeorm';

export class AddActivityComment1554323679399 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await this._createColumns(queryRunner);
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropColumn('activity_log', 'comment');
}

private async _createColumns(queryRunner: QueryRunner) {
await queryRunner.addColumn(
'activity_log',
new TableColumn({
name: 'comment',
type: 'varchar',
length: '255',
isNullable: true
})
);
}
}
3 changes: 3 additions & 0 deletions src/models/activity-log.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class ActivityLog {
@CreateDateColumn({ name: 'created_at', nullable: false })
public createdAt: Date;

@Column({ type: 'varchar', length: 255, nullable: true })
public comment?: string;

constructor(private activityLog?: Partial<ActivityLog>) {
if (activityLog) {
Object.assign(this, activityLog);
Expand Down

0 comments on commit 95dddeb

Please sign in to comment.