Skip to content

Overview

The CommonGrants.Models namespace contains a standard models that are used by CommonGrants API routes.

The most common use for the CommonGrants.Models namespace is extending the OpportunityBase model with a set of custom fields. The quickstart has a more in depth tutorial, but here’s a quick example of how you can add support for custom fields:

import "@common-grants/core"
// Exposes the `Fields` and `Models` namespaces so that they can be accessed
// without a `CommonGrants` prefix
using CommonGrants;
model ProgramArea extends Fields.CustomField {
name: "programArea";
fieldType: Fields.CustomFieldType.string;
value: string;
description: "Primary focus area of the grant program.";
}
// Create a custom Opportunity type using the template
model CustomOpportunity extends Models.OpportunityBase {
@example(#{
programArea: #{
name: "programArea",
fieldType: Fields.CustomFieldType.string,
value: "Healthcare Innovation",
description: "Primary focus area of the grant program.",
},
})
customFields: {
programArea: ProgramArea;
};
}