diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e349567..e419b32 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,7 +48,7 @@ build-production: services: - docker:dind script: - - docker login $REGISTRY_URL -u $NWP_REGISTRY_USER -p $NWP_REGISTRY_PASS + - docker login $REGISTRY_URL -u $BKA_REGISTRY_USER -p $BKA_REGISTRY_PASS - docker build -t $REGISTRY_IMAGE:$VERSION_PRODUCTION . - docker push $REGISTRY_IMAGE:$VERSION_PRODUCTION - docker rmi $REGISTRY_IMAGE:$VERSION_PRODUCTION @@ -59,9 +59,9 @@ deploy-production: only: - devops-production script: - - kubectl config set-cluster k8s --server="${NWP_CLUSTER_HOST}" - - kubectl config set clusters.k8s.certificate-authority-data ${NWP_CLUSTER_CA} - - kubectl config set-credentials gitlab --token="${NWP_CLUSTER_TOKEN}" + - kubectl config set-cluster k8s --server="${BKA_CLUSTER_HOST}" + - kubectl config set clusters.k8s.certificate-authority-data ${BKA_CLUSTER_CA} + - kubectl config set-credentials gitlab --token="${BKA_CLUSTER_TOKEN}" - kubectl config set-context default --cluster=k8s --user=gitlab - kubectl config use-context default - sed -i "s//${VERSION_PRODUCTION}/g" k8s/production/deployment.yaml diff --git a/k8s/production/deployment.yaml b/k8s/production/deployment.yaml new file mode 100644 index 0000000..1f40d78 --- /dev/null +++ b/k8s/production/deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ppob-backend + namespace: empatnusabangsa-production +spec: + selector: + matchLabels: + app: ppob-backend + replicas: 1 + template: + metadata: + labels: + app: ppob-backend + spec: + containers: + - name: ppob-backend + image: registry-harbor.app.bangun-kreatif.com/empatnusabangsa/ppob-backend: + ports: + - containerPort: 5000 + envFrom: + - secretRef: + name: ppob-backend-env + volumeMounts: + - name: storage + mountPath: /home/node/files + volumes: + - name: storage + persistentVolumeClaim: + claimName: ppob-backend-pvc + imagePullSecrets: + - name: regcred + diff --git a/k8s/production/ingress.yaml b/k8s/production/ingress.yaml new file mode 100644 index 0000000..dcd95d9 --- /dev/null +++ b/k8s/production/ingress.yaml @@ -0,0 +1,24 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ppob-backend + namespace: empatnusabangsa-production + annotations: + kubernetes.io/ingress.class: "traefik" + cert-manager.io/cluster-issuer: letsencrypt-prod +spec: + rules: + - host: "ppob-backend.k3s.bangun-kreatif.com" + http: + paths: + - pathType: Prefix + path: / + backend: + service: + name: ppob-backend + port: + number: 5000 + tls: + - hosts: + - "ppob-backend.k3s.bangun-kreatif.com" + secretName: ppob-backend-k3s-bangun-kreatif-com-tls diff --git a/k8s/production/namespace.yaml b/k8s/production/namespace.yaml new file mode 100644 index 0000000..823e09a --- /dev/null +++ b/k8s/production/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: empatnusabangsa-production diff --git a/k8s/production/pvc.yaml b/k8s/production/pvc.yaml new file mode 100644 index 0000000..0212116 --- /dev/null +++ b/k8s/production/pvc.yaml @@ -0,0 +1,13 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: ppob-backend-pvc + namespace : empatnusabangsa-production + annotations: + volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi diff --git a/k8s/production/secret.example copy.yaml b/k8s/production/secret.example copy.yaml new file mode 100644 index 0000000..519f171 --- /dev/null +++ b/k8s/production/secret.example copy.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Secret +metadata: + name: ppob-backend-env + namespace: empatnusabangsa-production +type: Opaque +stringData: + PORT: + SECRET: + + DATABASE_HOST: + DATABASE_NAME: + DATABASE_USERNAME: + DATABASE_PASSWORD: + DATABASE_PORT: + DATABASE_CLIENT: diff --git a/k8s/production/service.yaml b/k8s/production/service.yaml new file mode 100644 index 0000000..e583ffa --- /dev/null +++ b/k8s/production/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: ppob-backend + namespace: empatnusabangsa-production + labels: + run: ppob-backend +spec: + ports: + - port: 5000 + protocol: TCP + selector: + app: ppob-backend diff --git a/k8s/staging/pvc.yaml b/k8s/staging/pvc.yaml index 5b3fc42..7f882c3 100644 --- a/k8s/staging/pvc.yaml +++ b/k8s/staging/pvc.yaml @@ -10,4 +10,4 @@ spec: - ReadWriteMany resources: requests: - storage: 10Gi + storage: 512m diff --git a/src/product/product.service.ts b/src/product/product.service.ts index db2aed9..0a29b68 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -84,38 +84,31 @@ export class ProductService { where: { product: productData.id, partner: partnerData.id, + endDate: IsNull(), }, }); - } else { dataHistoryPrice = await this.productHistoryPrice.findOne({ product: productData, partner: IsNull(), + endDate: IsNull(), }); } - if (!dataHistoryPrice) { - await this.productHistoryPrice.insert({ - product: productData, - mark_up_price: it[4], - price: it[3], - type: productType.NORMAL, - startDate: new Date(), - partner: it[6] != '-' ? partnerData : null, - }); - } else { - dataHistoryPrice.endDate = new Date(); - await this.productHistoryPrice.save(dataHistoryPrice); - - await this.productHistoryPrice.insert({ - product: productData, - mark_up_price: it[4], - price: it[3], - type: productType.NORMAL, - startDate: new Date(), - partner: it[6] != '-' ? partnerData : null, + if (dataHistoryPrice) { + await this.productHistoryPrice.update(dataHistoryPrice.id, { + endDate: new Date(), }); } + + await this.productHistoryPrice.insert({ + product: productData, + mark_up_price: it[4], + price: it[3], + type: productType.NORMAL, + startDate: new Date(), + partner: it[6] != '-' ? partnerData : null, + }); } else { let partnerData; if (it[6] != '-' && it[6] != '') { diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 6f1c04d..ddf69ae 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -762,7 +762,7 @@ export class TransactionService { `${coaType[coaType.EXPENSE]}-SYSTEM`, ); - if (userData.partner) { + if (!userData.partner) { //GET SALES supervisorData = await this.calculateCommission( supervisorData, @@ -1062,7 +1062,7 @@ export class TransactionService { 'status', 'userData.name', ]) - .orderBy('transaction.created_at','DESC'); + .orderBy('transaction.created_at', 'DESC'); if (startDate && endDate) { baseQuery.andWhere(