| 1 | import netRequest from '.'; |
| 2 | |
| 3 | export enum TracingType { |
| 4 | EVENT = 'event', // 事件 |
| 5 | } |
| 6 | |
| 7 | export enum TracingTag { |
| 8 | AccountAdd = 'AccountAdd', // 账号添加 |
| 9 | VideoPul = 'VideoPul', // 视频发布 |
| 10 | OpenProjectUse = 'OpenProjectUse', // 开源项目调用 |
| 11 | } |
| 12 | |
| 13 | export interface Tracing { |
| 14 | id: string; |
| 15 | userId: string; |
| 16 | type: TracingType; |
| 17 | tag: TracingTag; |
| 18 | accountId?: number; // 平台账号ID |
| 19 | desc?: string; |
| 20 | dataId?: string; // 关联数据id |
| 21 | createTime: string; |
| 22 | updateTime: string; |
| 23 | } |
| 24 | |
| 25 | export class TracingApi { |
| 26 | // 创建跟踪-账号添加 |
| 27 | async createTracingAccountAdd(account: { |
| 28 | id: number; |
| 29 | desc?: string; |
| 30 | }): Promise<Tracing | null> { |
| 31 | const inData: { |
| 32 | type: TracingType; |
| 33 | tag: string; |
| 34 | accountId?: number; // 平台账号ID |
| 35 | desc?: string; |
| 36 | dataId?: string; // 关联数据id |
| 37 | } = { |
| 38 | type: TracingType.EVENT, |
| 39 | tag: TracingTag.AccountAdd, |
| 40 | accountId: account.id, |
| 41 | desc: account.desc, |
| 42 | dataId: account.id + '', |
| 43 | }; |
| 44 | |
| 45 | const res = await netRequest<{ |
| 46 | data: Tracing; |
| 47 | code: number; |
| 48 | msg: string; |
| 49 | }>({ |
| 50 | method: 'POST', |
| 51 | url: 'tracing', |
| 52 | body: inData, |
| 53 | isToken: true, |
| 54 | }); |
| 55 | const { |
| 56 | status, |
| 57 | data: { data, code }, |
| 58 | } = res; |
| 59 | |
| 60 | if (status !== 200 && status !== 201) return null; |
| 61 | if (!!code) return null; |
| 62 | return data; |
| 63 | } |
| 64 | |
| 65 | // 创建跟踪-视频发布 |
| 66 | async createTracingVideoPul(inData: { |
| 67 | accountId: number; |
| 68 | dataId: string; // 视频发布数据ID |
| 69 | desc?: string; |
| 70 | }): Promise<Tracing | null> { |
| 71 | const body: { |
| 72 | type: TracingType; |
| 73 | tag: string; |
| 74 | accountId?: number; // 平台账号ID |
| 75 | desc?: string; |
| 76 | dataId?: string; // 关联数据id |
| 77 | } = { |
| 78 | type: TracingType.EVENT, |
| 79 | tag: TracingTag.VideoPul, |
| 80 | accountId: inData.accountId, |
| 81 | desc: inData.desc, |
| 82 | dataId: inData.dataId + '', |
| 83 | }; |
| 84 | |
| 85 | const res = await netRequest<{ |
| 86 | data: Tracing; |
| 87 | code: number; |
| 88 | msg: string; |
| 89 | }>({ |
| 90 | method: 'POST', |
| 91 | url: 'tracing', |
| 92 | body: body, |
| 93 | isToken: true, |
| 94 | }); |
| 95 | |
| 96 | const { |
| 97 | status, |
| 98 | data: { data, code }, |
| 99 | } = res; |
| 100 | if (status !== 200 && status !== 201) return null; |
| 101 | if (!!code) return null; |
| 102 | return data; |
| 103 | } |
| 104 | |
| 105 | // 创建跟踪-开源项目调用 |
| 106 | async createTracingOpenProjectUse(inData: { |
| 107 | desc?: string; |
| 108 | }): Promise<Tracing | null> { |
| 109 | const body: { |
| 110 | type: TracingType; |
| 111 | tag: string; |
| 112 | accountId?: number; // 平台账号ID |
| 113 | desc?: string; |
| 114 | dataId?: string; // 关联数据id |
| 115 | } = { |
| 116 | type: TracingType.EVENT, |
| 117 | tag: TracingTag.OpenProjectUse, |
| 118 | desc: inData.desc, |
| 119 | }; |
| 120 | |
| 121 | const res = await netRequest<{ |
| 122 | data: Tracing; |
| 123 | code: number; |
| 124 | msg: string; |
| 125 | }>({ |
| 126 | method: 'POST', |
| 127 | url: 'tracing', |
| 128 | body: body, |
| 129 | }); |
| 130 | const { |
| 131 | status, |
| 132 | data: { data, code }, |
| 133 | } = res; |
| 134 | if (status !== 200 && status !== 201) return null; |
| 135 | if (!!code) return null; |
| 136 | return data; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | export const tracingApi = new TracingApi(); |
| 141 |