From fa1b249b4052aa6c4b186623b022dba4d1c4b5d8 Mon Sep 17 00:00:00 2001 From: glennmichael123 Date: Thu, 2 Jan 2025 18:09:11 +0800 Subject: [PATCH] chore: wip --- storage/framework/core/orm/src/utils.ts | 8 ++++---- storage/framework/orm/src/models/AccessToken.ts | 4 +++- storage/framework/orm/src/models/Deployment.ts | 4 ++-- storage/framework/orm/src/models/Error.ts | 4 +++- storage/framework/orm/src/models/PaymentMethod.ts | 6 ++---- storage/framework/orm/src/models/Post.ts | 4 ++-- storage/framework/orm/src/models/Product.ts | 4 +++- storage/framework/orm/src/models/Project.ts | 4 +++- storage/framework/orm/src/models/Release.ts | 4 +++- storage/framework/orm/src/models/Subscriber.ts | 4 +++- storage/framework/orm/src/models/SubscriberEmail.ts | 4 +++- storage/framework/orm/src/models/Subscription.ts | 4 ++-- storage/framework/orm/src/models/Team.ts | 4 +++- storage/framework/orm/src/models/Transaction.ts | 6 ++---- storage/framework/orm/src/models/User.ts | 10 ++-------- 15 files changed, 40 insertions(+), 34 deletions(-) diff --git a/storage/framework/core/orm/src/utils.ts b/storage/framework/core/orm/src/utils.ts index 1c234232b..31948e456 100644 --- a/storage/framework/core/orm/src/utils.ts +++ b/storage/framework/core/orm/src/utils.ts @@ -1732,10 +1732,10 @@ export async function generateModelString( if (!model) return undefined - ${relationStringThisMany} - ${relationStringThisBelong} - const data = new ${modelName}Model(model as ${modelName}Type) + const result = await this.mapWith(model) + + const data = new ${modelName}Model(result as ${modelName}Type) cache.getOrSet(\`${formattedModelName}:\${id}\`, JSON.stringify(model)) @@ -2204,7 +2204,7 @@ export async function generateModelString( if (!model) return undefined - + const instance = new ${modelName}Model(null) const result = await instance.mapWith(model) diff --git a/storage/framework/orm/src/models/AccessToken.ts b/storage/framework/orm/src/models/AccessToken.ts index bca0411c1..93c533c4d 100644 --- a/storage/framework/orm/src/models/AccessToken.ts +++ b/storage/framework/orm/src/models/AccessToken.ts @@ -91,7 +91,9 @@ export class AccessTokenModel { if (!model) return undefined - const data = new AccessTokenModel(model as AccessTokenType) + const result = await this.mapWith(model) + + const data = new AccessTokenModel(result as AccessTokenType) cache.getOrSet(`accesstoken:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Deployment.ts b/storage/framework/orm/src/models/Deployment.ts index 4795e281c..52202a540 100644 --- a/storage/framework/orm/src/models/Deployment.ts +++ b/storage/framework/orm/src/models/Deployment.ts @@ -111,9 +111,9 @@ export class DeploymentModel { if (!model) return undefined - model.user = await this.userBelong() + const result = await this.mapWith(model) - const data = new DeploymentModel(model as DeploymentType) + const data = new DeploymentModel(result as DeploymentType) cache.getOrSet(`deployment:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Error.ts b/storage/framework/orm/src/models/Error.ts index 32488d755..4f53dbe21 100644 --- a/storage/framework/orm/src/models/Error.ts +++ b/storage/framework/orm/src/models/Error.ts @@ -95,7 +95,9 @@ export class ErrorModel { if (!model) return undefined - const data = new ErrorModel(model as ErrorType) + const result = await this.mapWith(model) + + const data = new ErrorModel(result as ErrorType) cache.getOrSet(`error:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/PaymentMethod.ts b/storage/framework/orm/src/models/PaymentMethod.ts index 2bfc8034a..cddea5b1b 100644 --- a/storage/framework/orm/src/models/PaymentMethod.ts +++ b/storage/framework/orm/src/models/PaymentMethod.ts @@ -117,11 +117,9 @@ export class PaymentMethodModel { if (!model) return undefined - model.transactions = await this.transactionsHasMany() - - model.user = await this.userBelong() + const result = await this.mapWith(model) - const data = new PaymentMethodModel(model as PaymentMethodType) + const data = new PaymentMethodModel(result as PaymentMethodType) cache.getOrSet(`paymentmethod:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Post.ts b/storage/framework/orm/src/models/Post.ts index 6c91b6b33..98e480fe4 100644 --- a/storage/framework/orm/src/models/Post.ts +++ b/storage/framework/orm/src/models/Post.ts @@ -92,9 +92,9 @@ export class PostModel { if (!model) return undefined - model.user = await this.userBelong() + const result = await this.mapWith(model) - const data = new PostModel(model as PostType) + const data = new PostModel(result as PostType) cache.getOrSet(`post:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Product.ts b/storage/framework/orm/src/models/Product.ts index 8419e13c1..72b5c07f9 100644 --- a/storage/framework/orm/src/models/Product.ts +++ b/storage/framework/orm/src/models/Product.ts @@ -102,7 +102,9 @@ export class ProductModel { if (!model) return undefined - const data = new ProductModel(model as ProductType) + const result = await this.mapWith(model) + + const data = new ProductModel(result as ProductType) cache.getOrSet(`product:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Project.ts b/storage/framework/orm/src/models/Project.ts index b6d41d992..e8925c97a 100644 --- a/storage/framework/orm/src/models/Project.ts +++ b/storage/framework/orm/src/models/Project.ts @@ -89,7 +89,9 @@ export class ProjectModel { if (!model) return undefined - const data = new ProjectModel(model as ProjectType) + const result = await this.mapWith(model) + + const data = new ProjectModel(result as ProjectType) cache.getOrSet(`project:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Release.ts b/storage/framework/orm/src/models/Release.ts index 8da4d9581..a286cafd0 100644 --- a/storage/framework/orm/src/models/Release.ts +++ b/storage/framework/orm/src/models/Release.ts @@ -80,7 +80,9 @@ export class ReleaseModel { if (!model) return undefined - const data = new ReleaseModel(model as ReleaseType) + const result = await this.mapWith(model) + + const data = new ReleaseModel(result as ReleaseType) cache.getOrSet(`release:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Subscriber.ts b/storage/framework/orm/src/models/Subscriber.ts index 13b07107b..922cf3a25 100644 --- a/storage/framework/orm/src/models/Subscriber.ts +++ b/storage/framework/orm/src/models/Subscriber.ts @@ -80,7 +80,9 @@ export class SubscriberModel { if (!model) return undefined - const data = new SubscriberModel(model as SubscriberType) + const result = await this.mapWith(model) + + const data = new SubscriberModel(result as SubscriberType) cache.getOrSet(`subscriber:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/SubscriberEmail.ts b/storage/framework/orm/src/models/SubscriberEmail.ts index ee707306b..ad6fc4de4 100644 --- a/storage/framework/orm/src/models/SubscriberEmail.ts +++ b/storage/framework/orm/src/models/SubscriberEmail.ts @@ -86,7 +86,9 @@ export class SubscriberEmailModel { if (!model) return undefined - const data = new SubscriberEmailModel(model as SubscriberEmailType) + const result = await this.mapWith(model) + + const data = new SubscriberEmailModel(result as SubscriberEmailType) cache.getOrSet(`subscriberemail:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Subscription.ts b/storage/framework/orm/src/models/Subscription.ts index 03b6e294b..fb715577e 100644 --- a/storage/framework/orm/src/models/Subscription.ts +++ b/storage/framework/orm/src/models/Subscription.ts @@ -120,9 +120,9 @@ export class SubscriptionModel { if (!model) return undefined - model.user = await this.userBelong() + const result = await this.mapWith(model) - const data = new SubscriptionModel(model as SubscriptionType) + const data = new SubscriptionModel(result as SubscriptionType) cache.getOrSet(`subscription:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Team.ts b/storage/framework/orm/src/models/Team.ts index 870361017..7ef98fd20 100644 --- a/storage/framework/orm/src/models/Team.ts +++ b/storage/framework/orm/src/models/Team.ts @@ -105,7 +105,9 @@ export class TeamModel { if (!model) return undefined - const data = new TeamModel(model as TeamType) + const result = await this.mapWith(model) + + const data = new TeamModel(result as TeamType) cache.getOrSet(`team:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/Transaction.ts b/storage/framework/orm/src/models/Transaction.ts index ddcfda63f..b1cc0ccf2 100644 --- a/storage/framework/orm/src/models/Transaction.ts +++ b/storage/framework/orm/src/models/Transaction.ts @@ -114,11 +114,9 @@ export class TransactionModel { if (!model) return undefined - model.user = await this.userBelong() - - model.payment_method = await this.paymentMethodBelong() + const result = await this.mapWith(model) - const data = new TransactionModel(model as TransactionType) + const data = new TransactionModel(result as TransactionType) cache.getOrSet(`transaction:${id}`, JSON.stringify(model)) diff --git a/storage/framework/orm/src/models/User.ts b/storage/framework/orm/src/models/User.ts index 315b1150d..0d5ff219c 100644 --- a/storage/framework/orm/src/models/User.ts +++ b/storage/framework/orm/src/models/User.ts @@ -136,15 +136,9 @@ export class UserModel { if (!model) return undefined - model.deployments = await this.deploymentsHasMany() - - model.subscriptions = await this.subscriptionsHasMany() - - model.payment_methods = await this.paymentMethodsHasMany() + const result = await this.mapWith(model) - model.transactions = await this.transactionsHasMany() - - const data = new UserModel(model as UserType) + const data = new UserModel(result as UserType) cache.getOrSet(`user:${id}`, JSON.stringify(model))