Skip to content

Commit

Permalink
feat(schemas/task-reminder): 升级任务提醒
Browse files Browse the repository at this point in the history
  • Loading branch information
靳昌 committed Jun 3, 2020
1 parent 3c7eecf commit 187caba
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import './task'
import './user'
import './pagination'
import './project'
import './projectReminder'
import './search'
import './organization'
import './scenariofieldconfig'
Expand Down
46 changes: 46 additions & 0 deletions src/apis/projectReminder/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ProjectId } from 'teambition-types'

import { ProjectReminderSchema } from '../../schemas/ProjectReminder'
import { SDKFetch } from '../../SDKFetch'
import { SDK, CacheStrategy } from '../../SDK'

/**
* 获取项目级别的任务提醒规则
*/
export function getProjectRemindersFetch(
this: SDKFetch,
projectId: ProjectId
) {
return this.get<ProjectReminderSchema[]>(`projects/${projectId}/reminders`)
}

declare module '../../SDKFetch' {
interface SDKFetch {
getProjectReminders: typeof getProjectRemindersFetch
}
}

SDKFetch.prototype.getProjectReminders = getProjectRemindersFetch

/**
* 获取项目级别的任务提醒规则
*/
function getProjectReminders(
this: SDK,
projectId: ProjectId,
) {
return this.lift<ProjectReminderSchema>({
cacheValidate: CacheStrategy.Request,
query: { where: { _projectId: projectId } },
request: this.fetch.getProjectReminders(projectId),
tableName: 'ProjectReminder',
})
}

declare module '../../SDK' {
interface SDK {
getProjectReminders: typeof getProjectReminders
}
}

SDK.prototype.getProjectReminders = getProjectReminders
2 changes: 2 additions & 0 deletions src/apis/projectReminder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './get'
import './put'
32 changes: 32 additions & 0 deletions src/apis/projectReminder/put.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ProjectId } from 'teambition-types'

import { ProjectReminderSchema } from '../../schemas/ProjectReminder'
import { SDKFetch } from '../../SDKFetch'

interface Payload {
addReminders: Pick<ProjectReminderSchema, 'rule' | 'receivers'>[]
delReminders: Pick<ProjectReminderSchema, '_id'>[]
updateReminders: Pick<ProjectReminderSchema, '_id' | 'rule' | 'receivers'>[]
}

/**
* 更新项目级别的任务提醒规则
*/
export function updateProjectRemindersFetch(
this: SDKFetch,
projectId: ProjectId,
payload: Payload,
) {
return this.put<ProjectReminderSchema[]>(
`projects/${projectId}/reminders`,
payload
)
}

declare module '../../SDKFetch' {
interface SDKFetch {
updateProjectReminders: typeof updateProjectRemindersFetch
}
}

SDKFetch.prototype.updateProjectReminders = updateProjectRemindersFetch
25 changes: 25 additions & 0 deletions src/schemas/ProjectReminder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ProjectReminderId, ProjectId, UserId } from 'teambition-types'

import { SchemaDef, RDBType } from '../db'
import { schemaColl } from './schemas'
import { TaskReminderReceiverBaseOnRole } from './TaskReminder'

export interface ProjectReminderSchema {
_id: ProjectReminderId
_creatorId: UserId
_projectId: ProjectId
isDeleted: boolean
receivers: TaskReminderReceiverBaseOnRole[]
rule: string
}

const schema: SchemaDef<ProjectReminderSchema> = {
_id: { type: RDBType.STRING, primaryKey: true },
_creatorId: { type: RDBType.STRING },
_projectId: { type: RDBType.STRING },
isDeleted: { type: RDBType.BOOLEAN },
receivers: { type: RDBType.OBJECT },
rule: { type: RDBType.STRING },
}

schemaColl.add({ schema, name: 'ProjectReminder' })
9 changes: 7 additions & 2 deletions src/schemas/Task.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RDBType, Relationship, SchemaDef } from '../db'
import {
CustomFieldValue, ExecutorOrCreator, Reminder, VisibleOption,
CustomFieldValue, ExecutorOrCreator, DeprecatedReminder, VisibleOption,
OrganizationId, TaskDivisionType, ApprovalSchema, UrgeSchema
} from 'teambition-types'
import {
Expand Down Expand Up @@ -38,6 +38,7 @@ export interface TaskSchema {
divisions?: TaskDivisionType[]
dueDate: string | null
priority: TaskPriority
hasReminder: boolean
isDone: boolean
isArchived: boolean
isDeleted: boolean
Expand Down Expand Up @@ -72,7 +73,10 @@ export interface TaskSchema {
objectlinksCount: number
openId?: string
shareStatus: number
reminder: Reminder
/**
* @deprecated 兼容字段
*/
reminder: DeprecatedReminder
subtaskCount: {
total: number
done: number
Expand Down Expand Up @@ -202,6 +206,7 @@ const schema: SchemaDef<TaskSchema> = {
involvers: {
type: RDBType.OBJECT
},
hasReminder: { type: RDBType.BOOLEAN },
involveMembers: {
type: RDBType.LITERAL_ARRAY
},
Expand Down
65 changes: 65 additions & 0 deletions src/schemas/TaskReminder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { TaskReminderId, TaskId } from 'teambition-types'

import { RDBType, SchemaDef } from '../db'
import { schemaColl } from './schemas'
import { ProjectReminderSchema } from './ProjectReminder'

export enum ReminderRuleType {
startDate = 'startDate',
dueDate = 'dueDate',
custom = 'custom',
}

export enum ReminderUnit {
minute = 'minute',
hour = 'hour',
day = 'day',
}

export enum TaskReminderReceiverBaseOnRole {
executor = 'role/executor',
involver = 'role/involver',
creator = 'role/creator',
}

export enum TaskReminderSource {
task = 'source:task',
project = 'source:project',
}

interface TaskReminderBaseSchema {
_id: TaskReminderId
boundToObjectId: TaskId
boundToObjectType: 'task'
isDeleted: boolean
rule: string
}

// 来源于项目规则
interface TaskReminderBaseProjectSchema
extends TaskReminderBaseSchema,
Pick<ProjectReminderSchema, 'receivers'> {
labels: TaskReminderSource.task[]
}

// 来源于自身的规则
interface TaskReminderBaseOwnSchema extends TaskReminderBaseSchema {
labels: TaskReminderSource.project[]
receivers: string[]
}

export type TaskReminderSchema =
| TaskReminderBaseProjectSchema
| TaskReminderBaseOwnSchema

const schema: SchemaDef<TaskReminderSchema> = {
_id: { type: RDBType.STRING, primaryKey: true },
boundToObjectId: { type: RDBType.STRING },
boundToObjectType: { type: RDBType.STRING },
isDeleted: { type: RDBType.BOOLEAN },
labels: { type: RDBType.OBJECT },
receivers: { type: RDBType.OBJECT },
rule: { type: RDBType.STRING },
}

schemaColl.add({ schema, name: 'TaskReminder' })
4 changes: 4 additions & 0 deletions src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import './Preference'
export * from './Preference'
import './Project'
export * from './Project'
import './ProjectReminder'
export * from './ProjectReminder'
import './ProjectTag'
export * from './ProjectTag'
// import './ProjectTemplate' // 目前不需建表
Expand All @@ -57,6 +59,8 @@ import './Tasklist'
export * from './Tasklist'
import './TaskPrivilege'
export * from './TaskPrivilege'
import './TaskReminder'
export * from './TaskReminder'
import './UserMe'
export * from './UserMe'
import './Message'
Expand Down
51 changes: 37 additions & 14 deletions src/teambition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ declare module 'teambition-types' {
export type ProjectId = string & { kind: 'ProjectId' }
export type ProjectPortalMode = 'grid' | 'list' | 'table'
export type ProjectOrder = 'updated' | 'name' | 'recentVisit'
export type ProjectReminderId = string & { kind: 'ProjectReminderId' }
export type ProjectStatusActivityId = string & { kind: 'ProjectStatusActivityId' }
export type ProjectTagId = string & { kind: 'ProjectTagId' }
export type ProjectTemplateId = string & { kind: 'ProjectTemplateId' }
Expand All @@ -73,6 +74,7 @@ declare module 'teambition-types' {
export type TaskId = string & { kind: 'TaskId' }
export type TasklistId = string & { kind: 'TasklistId' }
export type TaskPrivilegeId = string & { kind: 'TaskPrivilegeId' }
export type TaskReminderId = string & { kind: 'TaskReminderId' }
export type TeamId = string & { kind: 'TeamId' }
export type TestcaseId = string & { kind: 'TestcaseId' }
export type TesthubId = string & { kind: 'TesthubId' }
Expand Down Expand Up @@ -116,9 +118,9 @@ declare module 'teambition-types' {
export type ProjectStatusDegree = 'normal' | 'risky' | 'urgent'
export type ProjectTagVisibleOption = 'organization' | 'involves'
export type ProjectTemplateVisibleOption = 'organization' | 'involves'
export type ReminderType = 'customize' | 'dueDate' | 'startDate' | 'unset' // 兼容旧版本,新功能开发请使用 ReminderRuleType
export type ReminderRuleType = 'startDate' | 'dueDate' | 'customize' | 'beforeStartDate' | 'beforeDueDate' | 'afterStartDate' | 'afterDueDate'
export type ReminderUnit = 'minute' | 'hour' | 'day'
export type DeprecatedReminderType = 'customize' | 'dueDate' | 'startDate' | 'unset' // 兼容旧版本,新功能开发请使用 ReminderRuleType
export type DeprecatedReminderRuleType = 'startDate' | 'dueDate' | 'customize' | 'beforeStartDate' | 'beforeDueDate' | 'afterStartDate' | 'afterDueDate'
export type DeprecatedReminderUnit = 'minute' | 'hour' | 'day'
export type ScenarioFieldConfigIcon = TaskScenarioFieldIcon | EventScenarioFieldIcon | TestcaseScenarioFieldIcon
export type ScenarioFieldConfigObjectType = 'task' | 'event' | 'testcase'
export type ScenarioFieldType =
Expand Down Expand Up @@ -245,32 +247,53 @@ declare module 'teambition-types' {
values: string[] // deprecated
}

export interface OnTimeReminderRule {
type: Extract<ReminderRuleType, 'startDate' | 'dueDate'>
/**
* @deprecated
*/
export interface DeprecatedOnTimeReminderRule {
type: Extract<DeprecatedReminderRuleType, 'startDate' | 'dueDate'>
date: null
}

export interface AbsoluteReminderRule {
type: Extract<ReminderRuleType, 'customize'>
/**
* @deprecated
*/
export interface DeprecatedAbsoluteReminderRule {
type: Extract<DeprecatedReminderRuleType, 'customize'>
date: string
}

export interface RelativeReminderRule {
type: Extract<ReminderRuleType, 'beforeStartDate' | 'beforeDueDate' | 'afterStartDate' | 'afterDueDate'>
/**
* @deprecated
*/
export interface DeprecatedRelativeReminderRule {
type: Extract<
DeprecatedReminderRuleType,
| 'beforeStartDate'
| 'beforeDueDate'
| 'afterStartDate'
| 'afterDueDate'
>
date: null
relative: {
unit: ReminderUnit
unit: DeprecatedReminderUnit
value: number
}
}

export type ReminderRule = OnTimeReminderRule | AbsoluteReminderRule | RelativeReminderRule
/**
* @deprecated 提醒规则,兼容字段,不推荐使用
*/
export type DeprecatedReminderRule =
| DeprecatedOnTimeReminderRule
| DeprecatedAbsoluteReminderRule
| DeprecatedRelativeReminderRule

export interface Reminder {
export interface DeprecatedReminder {
date: string // 兼容旧版本,新功能开发请使用 rules
type: ReminderType // 兼容旧版本,新功能开发请使用 rules
type: DeprecatedReminderType // 兼容旧版本,新功能开发请使用 rules
members: UserId[]
rules: ReminderRule[]
rules: DeprecatedReminderRule[]
_creatorId: UserId
}

Expand Down
Loading

0 comments on commit 187caba

Please sign in to comment.