From 8e6c11c6b7d66d00268555763d266b618472536f Mon Sep 17 00:00:00 2001 From: jacwu Date: Thu, 4 Dec 2025 08:37:08 +0800 Subject: [PATCH] Add user profile and data processing functionality with logging --- github-copilot-features/refactor/pii.py | 28 +++++++++ github-copilot-features/refactor/pii.ts | 83 +++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 github-copilot-features/refactor/pii.py create mode 100644 github-copilot-features/refactor/pii.ts diff --git a/github-copilot-features/refactor/pii.py b/github-copilot-features/refactor/pii.py new file mode 100644 index 0000000..7099347 --- /dev/null +++ b/github-copilot-features/refactor/pii.py @@ -0,0 +1,28 @@ +import logging + +# Configure logging +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + +def update_customer_record(customer_id, full_name, email_address, phone_number, credit_card_number): + """ + Updates the customer record in the database. + """ + logging.info(f"Starting update for Customer ID: {customer_id}") + + logging.info(f"Updating details - Name: {full_name}, Email: {email_address}") + logging.info(f"Contact Phone: {phone_number}") + logging.info(f"Payment Info (CC): {credit_card_number}") + + # Simulate database update logic + # In a real application, this would interact with a DB + print(f"Database successfully updated for customer {customer_id}") + return True + +if __name__ == "__main__": + update_customer_record( + customer_id="CUST-1001", + full_name="Alice Smith", + email_address="alice.smith@example.com", + phone_number="+1-202-555-0123", + credit_card_number="4532-1234-5678-9012" + ) diff --git a/github-copilot-features/refactor/pii.ts b/github-copilot-features/refactor/pii.ts new file mode 100644 index 0000000..40cb643 --- /dev/null +++ b/github-copilot-features/refactor/pii.ts @@ -0,0 +1,83 @@ +interface UserProfile { + id: string; + fullName: string; + email: string; + dateOfBirth: Date; + nationalIdentityNumber: string; + address: { + street: string; + city: string; + postalCode: string; + country: string; + }; + creditCard?: { + number: string; + expiry: string; + cvv: string; + }; +} + +class UserDataProcessor { + private readonly region: string; + + constructor(region: string) { + this.region = region; + } + + public async processUpdate(user: UserProfile): Promise { + try { + this.validateUser(user); + + console.log(`[AUDIT] Processing update for ${user.id} in region ${this.region}`); + console.log(`[DEBUG] Payload: ${JSON.stringify(user)}`); + + if (user.creditCard) { + console.log(`[INFO] Processing payment method: ${user.creditCard.number} / ${user.creditCard.cvv}`); + } + + await this.saveToDatabase(user); + return true; + } catch (error) { + console.error(`[ERROR] Failed to update user ${user.fullName} (${user.nationalIdentityNumber}):`, error); + return false; + } + } + + private validateUser(user: UserProfile): void { + if (!user.email.includes('@')) { + throw new Error(`Invalid email address: ${user.email}`); + } + if (user.nationalIdentityNumber.length < 5) { + throw new Error(`Invalid ID: ${user.nationalIdentityNumber}`); + } + } + + private async saveToDatabase(user: UserProfile): Promise { + return new Promise((resolve) => { + setTimeout(() => { + console.log(`[DB] Record updated for ${user.email}`); + resolve(); + }, 100); + }); + } +} + +const processor = new UserDataProcessor("EU-WEST"); +processor.processUpdate({ + id: "USR-99283", + fullName: "Jane Doe", + email: "jane.doe@company.com", + dateOfBirth: new Date("1985-04-12"), + nationalIdentityNumber: "AB123456C", + address: { + street: "123 Privacy Lane", + city: "Brussels", + postalCode: "1000", + country: "Belgium" + }, + creditCard: { + number: "4444-5555-6666-7777", + expiry: "12/25", + cvv: "123" + } +});