-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ActivePieces
committed
Apr 28, 2024
1 parent
cadb76d
commit eba8b0c
Showing
23 changed files
with
596 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './issues-requests' | ||
export * from './issue-dto' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Static, Type } from "@sinclair/typebox"; | ||
import { ApId, BaseModelSchema } from "@activepieces/shared"; | ||
|
||
export enum IssueStatus { | ||
ONGOING = 'ONGOING', | ||
RESOLEVED = 'RESOLEVED', | ||
} | ||
|
||
export const Issue = Type.Object({ | ||
...BaseModelSchema, | ||
projectId: ApId, | ||
flowId: ApId, | ||
status: Type.Enum(IssueStatus), | ||
count: Type.Number(), | ||
lastSeen: Type.String(), | ||
}) | ||
|
||
export type Issue = Static<typeof Issue> | ||
|
||
|
||
export const PopulatedIssue = Type.Composite([Issue, Type.Object({ | ||
flowDisplayName: Type.String() | ||
})]) | ||
|
||
export type PopulatedIssue = Static<typeof PopulatedIssue> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
import { Type, Static } from '@sinclair/typebox' | ||
import { ApId } from '@activepieces/shared' | ||
import { IssueStatus } from './issue-dto' | ||
|
||
export const ListIssuesParams = Type.Object({ | ||
projectId: ApId, | ||
cursor: Type.Optional(Type.String()), | ||
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100 })), | ||
}) | ||
export type ListIssuesParams = Static<typeof ListIssuesParams> | ||
|
||
export const UpdateIssueRequest = Type.Object({ | ||
projectId: ApId, | ||
flowId: ApId, | ||
status: Type.Enum(IssueStatus), | ||
}) | ||
|
||
export type UpdateIssueRequest = Static<typeof UpdateIssueRequest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/server/api/src/app/database/migration/sqlite/1714255928781-AddIssueEntitySqlite.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { logger } from "@activepieces/server-shared"; | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class AddIssueEntitySqlite1714255928781 implements MigrationInterface { | ||
name = 'AddIssueEntitySqlite1714255928781' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
logger.info({ name: 'AddIssueEntitySqlite1714255928781' }, 'up'); | ||
await queryRunner.query(` | ||
CREATE TABLE "issue" ( | ||
"id" varchar(21) PRIMARY KEY NOT NULL, | ||
"created" datetime NOT NULL DEFAULT (datetime('now')), | ||
"updated" datetime NOT NULL DEFAULT (datetime('now')), | ||
"projectId" varchar(21) NOT NULL, | ||
"flowId" varchar(21) NOT NULL, | ||
"status" varchar CHECK("status" IN ('ONGOING', 'RESOLEVED')) NOT NULL, | ||
"count" integer NOT NULL, | ||
"lastSeen" datetime NOT NULL, | ||
CONSTRAINT "REL_6c7309a7ac3112d264f5d7b49f" UNIQUE ("flowId"), | ||
CONSTRAINT "fk_issue_flow_id" FOREIGN KEY ("flowId") REFERENCES "flow" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, | ||
CONSTRAINT "fk_issue_project_id" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE ON UPDATE RESTRICT | ||
) | ||
`); | ||
await queryRunner.query(` | ||
CREATE UNIQUE INDEX "idx_issue_flow_id" ON "issue" ("flowId") | ||
`); | ||
await queryRunner.query(` | ||
CREATE INDEX "idx_issue_project_id_flow_id" ON "issue" ("projectId", "flowId") | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP INDEX "idx_issue_project_id_flow_id" | ||
`); | ||
await queryRunner.query(` | ||
DROP INDEX "idx_issue_flow_id" | ||
`); | ||
await queryRunner.query(` | ||
DROP TABLE "issue" | ||
`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/server/api/src/app/ee/issues/issues-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox' | ||
import { issuesService } from './issues-service' | ||
import { ListIssuesParams } from '@activepieces/ee-shared' | ||
import { Permission, PrincipalType } from '@activepieces/shared' | ||
|
||
export const issuesController: FastifyPluginAsyncTypebox = async (app) => { | ||
app.get('/', ListIssuesRequest, async (req) => { | ||
return issuesService.list({ | ||
projectId: req.query.projectId, | ||
cursor: req.query.cursor, | ||
limit: req.query.limit ?? 10, | ||
}) | ||
}) | ||
|
||
} | ||
|
||
const ListIssuesRequest = { | ||
config: { | ||
allowedPrincipals: [ | ||
PrincipalType.USER, | ||
], | ||
permission: Permission.READ_ACTIVITY, | ||
}, | ||
schema: { | ||
querystring: ListIssuesParams, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { EntitySchema } from 'typeorm' | ||
import { | ||
ApIdSchema, | ||
BaseColumnSchemaPart, | ||
TIMESTAMP_COLUMN_TYPE, | ||
} from '../../database/database-common' | ||
import { | ||
IssueStatus, | ||
Issue, | ||
} from '@activepieces/ee-shared' | ||
import { Flow, Project } from '@activepieces/shared' | ||
|
||
|
||
type IssueSchema = Issue & { | ||
project: Project | ||
flow: Flow | ||
} | ||
|
||
export const IssueEntity = new EntitySchema<IssueSchema>({ | ||
name: 'issue', | ||
columns: { | ||
...BaseColumnSchemaPart, | ||
projectId: { | ||
...ApIdSchema, | ||
}, | ||
flowId: { | ||
...ApIdSchema, | ||
}, | ||
status: { | ||
type: String, | ||
enum: IssueStatus, | ||
}, | ||
count: { | ||
type: Number, | ||
}, | ||
lastSeen: { | ||
type: TIMESTAMP_COLUMN_TYPE, | ||
} | ||
}, | ||
indices: [ | ||
{ | ||
name: 'idx_issue_flow_id', | ||
unique: true, | ||
columns: ['flowId'], | ||
}, | ||
{ | ||
name: 'idx_issue_project_id_flow_id', | ||
unique: false, | ||
columns: ['projectId', 'flowId'], | ||
}, | ||
], | ||
relations: { | ||
flow: { | ||
type: 'one-to-one', | ||
target: 'flow', | ||
cascade: true, | ||
onDelete: 'CASCADE', | ||
joinColumn: { | ||
name: 'flowId', | ||
referencedColumnName: 'id', | ||
foreignKeyConstraintName: 'fk_issue_flow_id', | ||
}, | ||
}, | ||
project: { | ||
type: 'many-to-one', | ||
target: 'project', | ||
cascade: true, | ||
onUpdate: 'RESTRICT', | ||
onDelete: 'CASCADE', | ||
joinColumn: { | ||
name: 'projectId', | ||
foreignKeyConstraintName: 'fk_issue_project_id', | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox' | ||
import { issuesController } from './issues-controller' | ||
|
||
export const issuesModule: FastifyPluginAsyncTypebox = async (app) => { | ||
await app.register(issuesController, { prefix: '/v1/issues' }) | ||
} |
101 changes: 101 additions & 0 deletions
101
packages/server/api/src/app/ee/issues/issues-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { databaseConnection } from '../../database/database-connection' | ||
import { buildPaginator } from '../../helper/pagination/build-paginator' | ||
import { paginationHelper } from '../../helper/pagination/pagination-utils' | ||
import { Issue, ListIssuesParams, UpdateIssueRequest, IssueStatus, PopulatedIssue } from '@activepieces/ee-shared' | ||
import { apId, SeekPage, isNil, ActivepiecesError, ErrorCode, spreadIfDefined } from '@activepieces/shared' | ||
import { IssueEntity } from './issues-entity' | ||
import dayjs from 'dayjs' | ||
import { flowService } from '../../flows/flow/flow.service' | ||
import { flowVersionService } from '../../flows/flow-version/flow-version.service' | ||
const repo = databaseConnection.getRepository(IssueEntity) | ||
|
||
export const issuesService = { | ||
async add({ projectId, flowId }: { flowId: string, projectId: string }): Promise<void> { | ||
await repo.createQueryBuilder() | ||
.insert() | ||
.into(IssueEntity) | ||
.values({ | ||
projectId, | ||
flowId, | ||
id: apId(), | ||
lastSeen: dayjs().toISOString(), | ||
count: 0, | ||
status: IssueStatus.ONGOING, | ||
created: dayjs().toISOString(), | ||
updated: dayjs().toISOString(), | ||
}) | ||
.orIgnore() | ||
.execute(); | ||
|
||
await this.update({ | ||
projectId: projectId, | ||
flowId: flowId, | ||
status: IssueStatus.ONGOING, | ||
}) | ||
}, | ||
async get(projectId: string, flowId: string): Promise<Issue | null> { | ||
return repo.findOneBy({ | ||
projectId: projectId, | ||
flowId: flowId, | ||
}) | ||
}, | ||
|
||
async getOrThrow(projectId: string, flowId: string): Promise<Issue> { | ||
const issue = await repo.findOneBy({ | ||
projectId: projectId, | ||
flowId: flowId, | ||
}) | ||
if (isNil(issue)) { | ||
throw new ActivepiecesError({ | ||
code: ErrorCode.ENTITY_NOT_FOUND, | ||
params: { | ||
message: `issue not found`, | ||
}, | ||
}) | ||
} | ||
return issue | ||
}, | ||
async list({ projectId, cursor, limit }: ListIssuesParams): Promise<SeekPage<PopulatedIssue>> { | ||
const decodedCursor = paginationHelper.decodeCursor(cursor ?? null) | ||
const paginator = buildPaginator({ | ||
entity: IssueEntity, | ||
query: { | ||
limit, | ||
order: 'ASC', | ||
afterCursor: decodedCursor.nextCursor, | ||
beforeCursor: decodedCursor.previousCursor, | ||
}, | ||
}) | ||
|
||
const query = repo.createQueryBuilder(IssueEntity.options.name).where({ | ||
projectId, | ||
}) | ||
|
||
const { data, cursor: newCursor } = await paginator.paginate(query) | ||
|
||
const populatedIssues = await Promise.all(data.map(async issue => { | ||
const flowVersion = await flowVersionService.getLatestLockedVersionOrThrow(issue.flowId); | ||
return { | ||
...issue, | ||
flowDisplayName: flowVersion.displayName, | ||
} | ||
})) | ||
return paginationHelper.createPage<PopulatedIssue>(populatedIssues, newCursor) | ||
}, | ||
|
||
// Updates the status of the issue and updates the coloumns `count` and `lastSeen` accordingly. | ||
async update({ projectId, flowId, status }: UpdateIssueRequest): Promise<void> { | ||
if (status != IssueStatus.RESOLEVED) { | ||
await repo.increment({ projectId, flowId }, 'count', 1); | ||
} | ||
await repo.update({ | ||
projectId, | ||
flowId, | ||
}, { | ||
...spreadIfDefined('lastSeen', status !== IssueStatus.RESOLEVED ? dayjs().toISOString() : undefined), | ||
...spreadIfDefined('count', status === IssueStatus.RESOLEVED ? 0 : undefined), | ||
status, | ||
updated: new Date().toISOString(), | ||
}) | ||
}, | ||
} |
Oops, something went wrong.