Feature: #84, BugFix #93, Init Free Plan, Selection type of Listing

This commit is contained in:
2024-08-27 20:01:56 +02:00
parent c1b72bbc12
commit 8721be4a90
14 changed files with 306 additions and 67 deletions

View File

@@ -10,7 +10,7 @@ import { ImageCropperComponent } from 'ngx-image-cropper';
import { QuillModule } from 'ngx-quill';
import { lastValueFrom } from 'rxjs';
import { User } from '../../../../../../bizmatch-server/src/models/db.model';
import { AutoCompleteCompleteEvent, Invoice, StripeSubscription, UploadParams, ValidationMessage, createDefaultUser, emailToDirName } from '../../../../../../bizmatch-server/src/models/main.model';
import { AutoCompleteCompleteEvent, Invoice, StripeSubscription, UploadParams, ValidationMessage, emailToDirName } from '../../../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../../../environments/environment';
import { ConfirmationComponent } from '../../../components/confirmation/confirmation.component';
import { ConfirmationService } from '../../../components/confirmation/confirmation.service';
@@ -111,10 +111,6 @@ export class AccountComponent {
this.subscriptions = await lastValueFrom(this.subscriptionService.getAllSubscriptions(this.user.email));
await this.synchronizeSubscriptions(this.subscriptions);
// if (this.subscriptions.length === 0) {
// this.subscriptions = [{ ended_at: null, start_date: Math.floor(new Date(this.user.created).getTime() / 1000), status: null, metadata: { plan: 'Free Plan' } }];
// }
this.profileUrl = this.user.hasProfile ? `${this.env.imageBaseUrl}/pictures/profile/${emailToDirName(this.user.email)}.avif?_ts=${new Date().getTime()}` : `/assets/images/placeholder.png`;
this.companyLogoUrl = this.user.hasCompanyLogo ? `${this.env.imageBaseUrl}/pictures/logo/${emailToDirName(this.user.email)}.avif?_ts=${new Date().getTime()}` : `/assets/images/placeholder.png`;
@@ -168,22 +164,9 @@ export class AccountComponent {
printInvoice(invoice: Invoice) {}
async updateProfile(user: User) {
if (this.user.customerType === 'buyer') {
const confirmed = await this.confirmationService.showConfirmation({ message: 'Are you sure you want to switch to Buyer ? All your listings as well as all your professionals informations will be deleted' });
if (confirmed) {
const id = this.user.id;
this.user = createDefaultUser(this.user.email, this.user.firstname, this.user.lastname, null);
this.user.customerType = 'buyer';
this.user.id = id;
this.imageService.deleteLogoImagesByMail(this.user.email);
this.imageService.deleteProfileImagesByMail(this.user.email);
} else {
this.user.customerType = 'professional';
return;
}
}
try {
await this.userService.save(this.user);
this.userService.changeUser(this.user);
this.messageService.addMessage({ severity: 'success', text: 'Account changes have been persisted', duration: 3000 });
this.validationMessagesService.clearMessages(); // Löschen Sie alle bestehenden Validierungsnachrichten
this.validationMessages = [];

View File

@@ -7,11 +7,12 @@
<label for="listingsCategory" class="block text-sm font-bold text-gray-700 mb-1">Listing category</label>
<ng-select
[readonly]="mode === 'edit'"
[items]="selectOptions?.listingCategories"
[items]="listingCategories"
bindLabel="name"
bindValue="value"
(ngModelChange)="changeListingCategory($event)"
[(ngModel)]="listing.listingsCategory"
[clearable]="false"
name="listingsCategory"
>
</ng-select>

View File

@@ -98,6 +98,7 @@ export class EditCommercialPropertyListingComponent {
data: BusinessListing;
userId: string;
typesOfCommercialProperty = [];
listingCategories = [];
env = environment;
ts = new Date().getTime();
quillModules = {
@@ -144,6 +145,13 @@ export class EditCommercialPropertyListingComponent {
async ngOnInit() {
const token = await this.keycloakService.getToken();
const keycloakUser = map2User(token);
const email = keycloakUser.email;
this.user = await this.userService.getByMail(email);
this.listingCategories = this.selectOptions.listingCategories
.filter(lc => lc.value === 'commercialProperty' || (this.user.customerSubType === 'broker' && lc.value === 'business'))
.map(e => {
return { name: e.name, value: e.value };
});
if (this.mode === 'edit') {
this.listing = (await lastValueFrom(this.listingsService.getListingById(this.id, 'commercialProperty'))) as CommercialPropertyListing;
} else {