Skip to main content

Class: OpportunityCollection

A class to perform CRUD opperations for Event/Opportunity Collection on Firestore.

Note: connectFirestoreEmulator is inherited for developing and testing purposes. DO NOT call connectFirestoreEmulator in production.

Example:

const config = { apiKey: ..., authDomain: ..., ...};const opportunityCollection = OpportunityCollection.create(config);const allOpportunites = await opportunityCollection.getOpportunities();

Hierarchy#

  • ICFirestoreCollection

    OpportunityCollection

Methods#

create#

Static create(options, name?): OpportunityCollection

A static method to create a new OpportunityCollection instance. The instance can be used to CRUD opportunities.

Parameters#

NameTypeDescription
optionsFirebaseOptionsSame as options used by initializeApp(options, name)
name?stringSame as name used by initializeApp(options, name)

Returns#

OpportunityCollection

A OpportunityCollection instance

See Firebase Documentation for more about initializeApp().

Example:

const config = { apiKey: ..., authDomain: ..., ...};const opportunityCollection = OpportunityCollection.create(config);const allOpportunites = await opportunityCollection.getOpportunities();

Defined in#

opportunity.ts:65


getOpportunities#

getOpportunities(eventQuery?): Promise<{ id: string }[]>

Get opportunites based on the given EventQuery.

Parameters#

NameTypeDescription
eventQuery?EventQueryThe filter and sort type used for fetching opportunities

Returns#

Promise<{ id: string }[]>

An array of opportunities after the filter as Event with id for the event

Example:

const eventQuery: EventQuery = defaultEventQuery;const queriedOpportunites = await opportunityCollection.getOpportunities(    eventQuery);const allOpportunites = await opportunityCollection.getOpportunities();allOpportunites.forEach((opportunity) => console.log(opportunity));

Defined in#

opportunity.ts:108


getOpportunityById#

getOpportunityById(id): Promise<null | { id: string }>

Get an exisitng opportunity based on given document id (generated by the Firestore).

Parameters#

NameTypeDescription
idstringThe document id for identifying the opportunity

Returns#

Promise<null | { id: string }>

An opportunity as Event with id if it's found; otherwise, it returns null

Example:

const id = "utJSlNLCImWrkTuxFpGM";const opportunity = await opportunityCollection.getOpportunityById(id);const { id, eventName } = opportunity;

Defined in#

opportunity.ts:156


createOpportunity#

createOpportunity(userId, event): Promise<string>

The company user create a new opportunity. This requires the company has been created before creating the opportunity.

Parameters#

NameTypeDescription
userIdstringThe Firestore's document id of the company user
eventEventThe new event/opportunity the user is creating

Returns#

Promise<string>

The document id for the new opportunity

Example:

const companyId = "pPn3FypudrthuNbop1wh";const event: Event = defaultEvent;const opportunityId = await opportunityCollection.createOpportunity(    companyId,    event);

Defined in#

opportunity.ts:179


updateOpportunity#

updateOpportunity(id, fields): Promise<void>

Update an existing opportunity, the opportunity is identified as Firestore's document id.

Parameters#

NameTypeDescription
idstringThe Firestore's document id of the event to be updated
fieldsPartial<Event>The fields with new values, it is a subset of Event interface

Returns#

Promise<void>

Example:

const id = "utJSlNLCImWrkTuxFpGM";const fields = { eventName: "A new event name" };await opportunityCollection.updateOpportunity(id, fields);

Defined in#

opportunity.ts:207


deleteOpportunity#

deleteOpportunity(id): Promise<void>

Delete an existing opportunity. The opportunity is not actually deleted from the firestore but its deleted field is set to true.

Parameters#

NameTypeDescription
idstringThe Firestore's document id of the event to be deleted

Returns#

Promise<void>

Example:

const id = "utJSlNLCImWrkTuxFpGM";await opportunityCollection.deleteOpportunity(id);

Defined in#

opportunity.ts:226


connectFirestoreEmulator#

connectFirestoreEmulator(host, port, options?): void

Parameters#

NameType
hoststring
portnumber
options?Object
options.mockUserToken?string | EmulatorMockTokenOptions

Returns#

void

Inherited from#

ICFirestoreCollection.connectFirestoreEmulator

Defined in#

collection.ts:39


createCompany#

createCompany(company): Promise<string>

Parameters#

NameType
companyCompany

Returns#

Promise<string>

Inherited from#

ICFirestoreCollection.createCompany

Defined in#

collection.ts:51

Constructors#

constructor#

new OpportunityCollection(options, name?)

Parameters#

NameTypeDescription
optionsFirebaseOptionsSame as options used by initializeApp(options, name)
name?stringSame as name used by initializeApp(options, name)

Overrides#

ICFirestoreCollection.constructor

Defined in#

opportunity.ts:43