generated from idea2app/Strapi-PNPM-Docker-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
[refactor] simplify Data Import script with MobX-RESTful-migrator #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0b039db
Initial plan
Copilot f8468bd
Add MobX-RESTful-migrator dependency and create refactored import scr…
Copilot d049c41
Complete data import script refactoring with working demonstrations a…
Copilot 7e8ffa2
Refactor to use mobx-strapi library and proper type separation as req…
Copilot 4323a84
Replace separate files with integrated refactored implementation
Copilot 0d95fbe
Unify logger classes and clean up legacy code as requested
Copilot 8b5e690
Clean up unused modules and improve logger implementation as requested
Copilot a6d1a60
[fix] many GitHub copilot bugs
TechQuery aaeaf9b
Move old logger method logic into new MigrationEventBus interface met…
Copilot c476305
[optimize] simplify Logger of Import Script
TechQuery d453b11
[remove] useless Batch mode of Import Script in new Migrator framework
TechQuery 11df574
[fix] some detail bugs
TechQuery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,49 +1,74 @@ | ||
| import { OrganizationData, Organization } from '../types'; | ||
| import { MigrationSchema, TargetPatch } from 'mobx-restful-migrator'; | ||
|
|
||
| import { SourceOrganization, TargetOrganization } from '../types'; | ||
| import { AddressTransformer } from './address-transformer'; | ||
| import { DateTransformer } from './date-transformer'; | ||
| import { ServiceTransformer } from './service-transformer'; | ||
| import { QualificationTransformer } from './qualification-transformer'; | ||
| import { UserTransformer } from './user-transformer'; | ||
| import { DataUtils } from '../utils/data-utils'; | ||
| import { TargetUserModel } from '../utils/strapi-api'; | ||
|
|
||
| export class DataTransformer { | ||
| static transformOrganization = ( | ||
| organization: Organization, | ||
| ): OrganizationData => ({ | ||
| name: organization['常用名称'] || organization.name || '', | ||
| code: organization['机构信用代码'] || organization.code || '', | ||
| entityType: DataUtils.transformEntityType( | ||
| organization['实体类型'] || organization.entityType, | ||
| ), | ||
| registrationCountry: DataUtils.transformRegistrationCountry( | ||
| organization['注册国籍'] || organization.registrationCountry, | ||
| ), | ||
| establishedDate: DateTransformer.parseDate( | ||
| organization['成立时间'] || organization.establishedDate, | ||
| ), | ||
| coverageArea: ServiceTransformer.extractCoverageFromDescription( | ||
| organization['机构/项目简介'] || organization.description, | ||
| ), | ||
| description: DataUtils.cleanDescription( | ||
| organization['机构/项目简介'] || organization.description || '', | ||
| ), | ||
| staffCount: DataUtils.parseStaffCount( | ||
| organization['机构/项目全职人数'] || organization.staffCount, | ||
| ), | ||
| address: AddressTransformer.transformAddress({ | ||
| export const migrationMapping: MigrationSchema< | ||
| SourceOrganization, | ||
| TargetOrganization | ||
| > = { | ||
| 常用名称: ({ 常用名称: value }) => ({ name: { value, unique: true } }), | ||
| 机构信用代码: 'code', | ||
| 实体类型: ({ 实体类型: value }) => ({ | ||
| entityType: { value: DataUtils.transformEntityType(value) }, | ||
| }), | ||
| 注册国籍: ({ 注册国籍: value }) => ({ | ||
| registrationCountry: { | ||
| value: DataUtils.transformRegistrationCountry(value), | ||
| }, | ||
| }), | ||
| 成立时间: ({ 成立时间: value }) => ({ | ||
| establishedDate: { value: DateTransformer.parseDate(value) }, | ||
| }), | ||
| '机构/项目简介': ({ ['机构/项目简介']: value }) => { | ||
| value ||= ''; | ||
| return { | ||
| description: { value: DataUtils.cleanDescription(value) }, | ||
| coverageArea: { | ||
| value: ServiceTransformer.extractCoverageFromDescription(value), | ||
| }, | ||
| }; | ||
| }, | ||
| '机构/项目全职人数': ({ ['机构/项目全职人数']: value }) => ({ | ||
| staffCount: { value: DataUtils.parseStaffCount(value) }, | ||
| }), | ||
| 注册地: ({ 注册地, 具体地址 }) => { | ||
| const addressData = { | ||
| province: AddressTransformer.extractProvinceFromAddress( | ||
| organization['注册地'] || organization['具体地址'], | ||
| ), | ||
| city: AddressTransformer.extractCityFromAddress( | ||
| organization['注册地'] || organization['具体地址'], | ||
| 注册地 || 具体地址, | ||
| ), | ||
| city: AddressTransformer.extractCityFromAddress(注册地 || 具体地址), | ||
| district: AddressTransformer.extractDistrictFromAddress( | ||
| organization['注册地'] || organization['具体地址'], | ||
| 注册地 || 具体地址, | ||
| ), | ||
| street: organization['具体地址'] || organization.address?.street || '', | ||
| }), | ||
| services: ServiceTransformer.transformServices(organization), | ||
| internetContact: ServiceTransformer.transformContacts(organization), | ||
| qualifications: | ||
| QualificationTransformer.transformQualifications(organization), | ||
| }); | ||
| } | ||
| street: 具体地址 || '', | ||
| }; | ||
| return { | ||
| address: { value: AddressTransformer.transformAddress(addressData) }, | ||
| }; | ||
| }, | ||
| 机构官网: (row) => ({ | ||
| services: { value: ServiceTransformer.transformServices(row) }, | ||
| }), | ||
| 机构微信公众号: (row) => ({ | ||
| internetContact: { value: ServiceTransformer.transformContacts(row) }, | ||
| }), | ||
| 登记管理机关: (org) => ({ | ||
| qualifications: { | ||
| value: QualificationTransformer.transformQualifications(org), | ||
| }, | ||
| }), | ||
| 机构联系人联系人姓名: (org) => { | ||
| const value = UserTransformer.transformUser(org); | ||
|
|
||
| return ( | ||
| !value ? {} : { contactUser: { value, model: TargetUserModel } } | ||
| ) as TargetPatch<TargetOrganization>; | ||
| }, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.